Hello, it is possible to patch the Uploader component with a File received from backend? I want to be like in this photo, the file to be already uploaded with a File I get from the backend. I looked on Uploader API but nothing about patch a File. Also is possible when I click on the File to download the file? Thanks
|
// Using template configured the download icon
<form (ngSubmit)="onSubmit()" [formGroup]="messageForm">
<ejs-uploader #UploadFiles formControlName="UploadFiles" id="UploadFiles" [dropArea]="dropElement"
(removing)="onFileRemove($event)">
<ng-template #template="" let-data>
<span class='wrapper'>
<span class='name file-name'>{{data.name}}</span>
<span class='file-size'>{{data.size}} bytes</span>
<span class="upload-status">{{data.status}}</span>
</span>
<span class="fa fa-download" title="Download" (click)="download($event,data.name)"></span>
<span class="e-icons e-file-remove-btn" title="Remove" (click)="remove($event)"></span>
</ng-template>
</ejs-uploader>
<button>submit</button>
</form> |
|
onSubmit() {
var fileUpload = this.uploadObj.element.parentElement.querySelector(
'.e-hidden-file-input'
).files[0];
// var files = fileUpload.files;
var data = new FormData();
// for (var i = 0; i < files.length; i++) {
data.append(fileUpload.name, fileUpload);
// }
$.ajax({
type: 'POST',
url: 'https://localhost:44312/Home/Save',
contentType: false,
processData: false,
data: data,
success: function (message) { },
error: function () { },
});
}
public download(args, filename) {
let url = 'https://localhost:44312/Home/Download?filename=' + filename;
window.location.rel='nofollow' href = url;
} |
|
[AcceptVerbs("Post")]
public IActionResult Save(IList<IFormFile> UploadFiles)
{
var UploadFiles = Request.Form.Files;
try
{
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
else
{
Response.Clear();
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists.";
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "No Content";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
return Content("");
}
[HttpGet]
public FileResult Download(string filename)
{
var filePath = Path.Combine(
Directory.GetCurrentDirectory(),
"wwwroot");
IFileProvider provider = new PhysicalFileProvider(filePath);
IFileInfo fileInfo = provider.GetFileInfo(filename);
var readStream = fileInfo.CreateReadStream();
var mimeType = "application/pdf";
return File(readStream, mimeType, filename);
} |
|
|
And also part with with the Patch is possible? Thanks