コード例 #1
0
        public virtual HttpResponseMessage Get(long id)
        {
            var file   = fileUploadService.GetFile(id);
            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(file.Body)
            };

            result.Content.Headers.ContentDisposition =
                new ContentDispositionHeaderValue("attachment")
            {
                FileName = file.Name,
                Size     = file.Size
            };
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            return(result);
        }
コード例 #2
0
        public IActionResult GetFile(int id)
        {
            var file = _fileUploadService.GetFile(id);

            if (file == null)
            {
                ModelState.AddModelError("Message", "Cannot find the file");
                return(BadRequest(ModelState));
            }
            MemoryStream ms = new MemoryStream(file.FileData);

            //HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
            //response.Content = new StreamContent(ms);
            //response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            //{
            //    FileName = file.FileName
            //};
            //response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            return(File(ms, "application/octet-stream"));
        }