Esempio n. 1
0
        public async Task <IActionResult> ReturnDownloadActionResultAsync(Guid id, HttpResponse response)
        {
            var doc = await _dataContext.Documents.Where(x => x.ID == id).Select(x => new { x.MimeType, x.FileName, x.Length }).FirstOrDefaultAsync();

            if (doc == null)
            {
                _logger.LogError("Did not find the requested document in the database for the ID {0}.", id.ToString("D"));
                return(new NotFoundResult());
            }

            _logger.LogDebug("Setting up the Response with Attachment for ID {0}.", id.ToString("D"));
            response.ContentType   = "application/octet-stream";
            response.ContentLength = doc.Length;
            var cd = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = doc.FileName,
                Size     = doc.Length
            };

            response.Headers.Add("Content-Disposition", cd.ToString());

            var client = new DataLakeAPI(_config);

            var files = await client.ListFiles(id.ToString("D"));

            for (int i = 0; i < files.Count(); i++)
            {
                var file = await client.GetFile(string.Format("{0}_{1}.part", id, i));

                await file.CopyToAsync(response.Body);
            }

            return(new OkResult());
        }
        public override async Task <IActionResult> ReturnDownloadActionResultAsync(Guid id, HttpResponse response)
        {
            var doc = await _dataContext.Documents.Where(x => x.ID == id).Select(x => new { x.MimeType, x.FileName, x.Length }).FirstOrDefaultAsync();

            if (doc == null)
            {
                _logger.LogError("Did not find the requested document in the database for the ID {0:D}.", id);
                return(new NotFoundResult());
            }

            _logger.LogDebug("Setting up the Response with Attachment for document ID {0:D}.", id);

            response.ContentType   = "application/octet-stream";
            response.ContentLength = doc.Length;
            var cd = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = doc.FileName,
                Size     = doc.Length
            };

            response.Headers.Add("Content-Disposition", cd.ToString());

            var chunks = GetDocuments(id).ToArray();

            foreach (var chunk in chunks)
            {
                await chunk.DownloadToStreamAsync(response.Body);
            }

            return(new OkResult());
        }
Esempio n. 3
0
        public async Task <ActionResult> Get(string fileName)
        {
            var cd = new System.Net.Http.Headers.ContentDispositionHeaderValue("inline")
            {
                FileName = "Excel.xlsx"
            };

            Response.Headers.Add("Content-Disposition", cd.ToString());
            StreamContent stream = YOUR_STREAM_SOURCE
                                   byte[] content = await stream.ReadAsByteArrayAsync();

            return(File(content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
        }
        public async Task <IActionResult> ReturnDownloadActionResultAsync(Guid id, HttpResponse response)
        {
            var doc = await _dataContext.Documents.Where(x => x.ID == id).Select(x => new { x.MimeType, x.FileName, x.Length }).FirstOrDefaultAsync();

            if (doc == null)
            {
                _logger.LogError("Did not find the requested document in the database for the ID {0}.", id.ToString("D"));
                return(new NotFoundResult());
            }

            _logger.LogDebug("Setting up the Response with Attachment for ID {0}.", id.ToString("D"));
            response.ContentType   = "application/octet-stream";
            response.ContentLength = doc.Length;
            var cd = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = doc.FileName,
                Size     = doc.Length
            };

            response.Headers.Add("Content-Disposition", cd.ToString());

            var share = GetCloudShare();

            var count = GetDocuments(id).Count();

            _logger.LogDebug("Verifing that the share exists.");
            if (share.Exists())
            {
                for (int i = 0; i < count; i++)
                {
                    CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                    var fileRef = rootDir.GetFileReference(string.Format("{0}_{1}.part", id, i));

                    await fileRef.DownloadToStreamAsync(response.Body);

                    _logger.LogDebug("Added {0}_{1}.part to the Response Stream.", id, i);
                }
            }
            else
            {
                _logger.LogError("The Share specified in the config file does not exists within the Storage Account. The Specified Share in the config file is {0}", _config["Files:FileStorageShare"]);
                throw new Exception("The Share is not configured correctly.");
            }

            return(new OkResult());
        }