public static async Task <ActionResult> Download(string key) { var folder = FileUploadService.GetFolder(key); if (!folder.Exists()) { return(CreateError("The folder does not exist for key: " + key)); } var files = folder.GetFiles(); if (files.None()) { return(CreateError("There is no file for key: " + key)); } if (files.HasMany()) { return(CreateError("There are multiple files for the key: " + key)); } var file = files.Single(); return(new FileContentResult(await file.ReadAllBytesAsync(), "application/octet-stream") { FileDownloadName = file.Name }); }
public static async Task <object> CreateDownloadAction(byte[] data, string filename) { var key = Guid.NewGuid().ToString(); var folder = FileUploadService.GetFolder(key).EnsureExists(); await folder.GetFile(filename).WriteAllBytes(data); var url = "/temp-file/" + key; Context.Http.Perform(c => url = c.GetUrlHelper().Content("~" + url)); return(new { Download = url }); }
public static async Task <object> CreateDownloadAction(byte[] data, string filename) { var key = Guid.NewGuid().ToString(); var folder = FileUploadService.GetFolder(key).EnsureExists(); await folder.GetFile(filename).WriteAllBytesAsync(data); var url = "/temp-file/" + key; var http = Context.Current.Http(); if (http != null) { url = http?.GetUrlHelper().Content("~" + url); } return(new { Download = url }); }