Beispiel #1
0
        public async Task <IActionResult> DownloadAsync(string key)
        {
            var path = _fileUploadService.GetFileUploads(key).ToList();

            if (path == null || path.Count() == 0)
            {
                return(new BadRequestObjectResult("Không tìm thấy ảnh"));
            }

            if (!System.IO.File.Exists(path[0].FilePath))
            {
                return(new BadRequestObjectResult("Không tìm thấy ảnh"));
            }

            var memory = new MemoryStream();

            using (var stream = new FileStream(path[0].FilePath, FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;
            return(File(memory, "application/octet-stream", Path.GetFileName(path[0].FilePath)));
        }