Exemplo n.º 1
0
        public static HttpResponseMessage ProcessMaterialDownload(this MaterialModel material, string rootPathName = MaterialUploadModel.DefaultRootPathName)
        {
            material.NullCheck("material");

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            FileInfo destFileInfo = null;

            if (rootPathName.IsNullOrEmpty())
            {
                rootPathName = MaterialUploadModel.DefaultRootPathName;
            }

            if (material.Status == MaterualModelStatus.Inserted)
            {
                destFileInfo = GetTempUploadFilePath(material.ID, rootPathName, material.OriginalName);
            }

            IMaterialContentPersistManager persistManager =
                GetMaterialContentPersistManager(material.ID, destFileInfo);

            Stream stream = persistManager.GetMaterialContent(material.ID);

            result.Content = new StreamContent(stream);

            result.Content.Headers.ContentType =
                new MediaTypeHeaderValue(GetFileContentType(material.OriginalName));

            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("Attachment")
            {
                FileName = HttpContext.Current.EncodeFileNameByBrowser(material.OriginalName)
            };

            return(result);
        }