Ejemplo n.º 1
0
        public virtual HttpResponseMessage GetThumbnail(long id)
        {
            var file = fileUploadService.GetFileThumbnail(id);

            if (file == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var    result = new HttpResponseMessage(HttpStatusCode.OK);
            string ext    = Path.GetExtension(file.Name).ToLower();

            if (!neadThumbnailFileExt.Contains(ext))
            {
                if (ext == ".xls" || ext == ".xlsx")
                {
                    result.Content = new ByteArrayContent(Resources.Resource.Img_Excel.ToByteArray());
                }
                if (ext == ".doc" || ext == ".docx")
                {
                    result.Content = new ByteArrayContent(Resources.Resource.Img_Word.ToByteArray());
                }
            }
            else
            {
                if (file.Thumbnail != null)
                {
                    result.Content = new ByteArrayContent(file.Thumbnail);
                }
                else
                {
                    result.Content = new ByteArrayContent(Resources.Resource.Img_Blank.ToByteArray());
                }
            }

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

            return(result);
        }