I am trying to figure out how I can download the files I just uploaded via the file upload control.
I was hoping the code below would give me a link I could then click on to download the file from the list in the control.
After some digging it looked like the recommended approach was to use a template on the upload control, however it looks like you are limited on what you can pass in to the model for the template.
I have the following code:
I have specified this template: I am guessing by the errors that it doesn't like the FileUploadId, ProjectId or AttachmentName fields. Is there away to provide a different model to the template?
<script id="fileUploadTemplate" type="text/x-kendo-template">
<span class='k-progress'></span>
<div class='file-wrapper'>
<a href="/ProductFiles/Upload/DownloadFile?fileUploadId=#= FileUploadId #&Projectd=#= ProjectId #">#= AttachmentName #</a>
<button type='button' class='k-upload-action'></button>
</div>
</script>
@(Html.Kendo().Upload()
.Name("projectFiles")
.Files(
files => {foreach (var f in Model.ProjectUploads)
{
files.Add().Name(f.FileName).Extension(f.UploadType).Size(f.FileSize);
}
})
.Async(a => a
.Save("Save", "Upload", new { area="Products" })
.Remove("Remove", "Upload", new { area = "Products" })
.SaveField("files")
)
.Events(events=>events
.Upload("onProjectFileUpload")
.Remove("onProjectFileUpload")
).TemplateId("fileUploadTemplate")
)
my controller method is:
public FileStreamResult DownloadFile(int fileUploadId, int projectId)
{
var uploads = GetUploadsByProjectId(projectId);
var attachment = uploads.Where(up => up.FileUploadId == fileUploadId).FirstOrDefault();
if (attachment != null)
{
string contentType = "application/octetstream";
var fileStreamResult = new FileStreamResult(new FileStream(attachment.FilePath, FileMode.Open, FileAccess.Read), contentType);
fileStreamResult.FileDownloadName = attachment.FileName;
return fileStreamResult;
}
}
Given the above code, Is this the best way to implement this? Is there another way all together I should be looking at?
Thanks,
Nick