예제 #1
0
        public static async Task <DownloadFileResult> Create(string downloadName, string fullPath)
        {
            var r = new DownloadFileResult(downloadName);

            await using var fs = File.OpenRead(fullPath);
            await fs.CopyToAsync(r);

            r.Seek(0, SeekOrigin.Begin);
            return(r);
        }
예제 #2
0
        public async Task <Stream> Get(DownloadFileRequest request)
        {
            var filePath = Directory.GetFiles(outputDirectoryProvider.GetOutputDirectory(), $"{request.Id}.*").FirstOrDefault();

            if (filePath == null)
            {
                return(await NotFoundFileResult.Create());
            }
            else
            {
                var extension    = Path.GetExtension(filePath);
                var downloadName = $"{DateTime.Now:yyyyMMdd_HHmmss}{extension}";
                var result       = await DownloadFileResult.Create(downloadName, filePath);

                File.Delete(filePath);
                return(result);
            }
        }