Esempio n. 1
0
        public async Task <IActionResult> DownloadByIdAsync(int id, CancellationToken cancellationToken)
        {
            var item = await _attachmentService.GetByIdAsync(id, cancellationToken);

            if (item == null)
            {
                throw new EntityNotFoundException(nameof(FunctionInfo), id);
            }

            // force download here
            var fileName      = item.OriginalFileName;
            var savedFileName = Path.GetFileName(item.SavedFileName);
            var contentType   = "application/octet-stream";

            new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType);
            var fileLocation = _uriComposer.ComposeUploadPath(savedFileName);

            byte[] fileBytes = System.IO.File.ReadAllBytes(fileLocation);
            return(File(fileBytes, (contentType ?? "application/octet-stream"), fileName));
        }