Beispiel #1
0
        public FileContentResult Image(String uri)
        {
            String           contentType = "";
            String           fileName    = "";
            DownloadFileRDto file;

            try
            {
                FileRepository fileRespository = new FileRepository();
                file        = fileRespository.Download(uri);
                fileName    = file.FileName;
                contentType = getImageContentType(fileName);
                if (String.IsNullOrEmpty(contentType))
                {
                    throw new Exception("this is not an image file ");
                }
            }
            catch (Exception ex) {
                return(null);
            }
            return(new FileContentResult(file.File, contentType));
        }
Beispiel #2
0
        /// <summary>
        /// 设置文件名
        /// </summary>
        /// <param name="info"></param>
        protected virtual void SetFileName(OrderProductEntity info)
        {
            if (info == null || !info.HasSaveProperty(it => it.Product.Id) || info.Product == null || info.Product.Id == 0 || info.FileByte != null)
            {
                return;
            }
            if (info.SaveType == SaveType.Modify)
            {
                var dataEntity = Repository.Get <OrderProductEntity>(info.Id);
                if (dataEntity.Product != null && dataEntity.Product.Id == info.Product.Id)
                {
                    info.FileName = dataEntity.FileName;
                    return;
                }
            }
            var product = Repository.Get <ProductEntity>(info.Product.Id);

            if (product == null)
            {
                return;
            }
            info.FileName = product.FileName;
            if (string.IsNullOrEmpty(info.FileName))
            {
                product.Goods = Repository.Get <GoodsEntity>(product.Goods.Id);
                info.FileName = product.Goods.FileName;
            }
            if (string.IsNullOrEmpty(info.FileName))
            {
                return;
            }
            info.FileName = string.Format("{0}.l{1}", info.FileName, Path.GetExtension(info.FileName));
            info.FileByte = FileRepository.Download(info.FileName);
            if (info.FileByte == null)
            {
                return;
            }
            info.FileName = string.Format("Files/Images/OrderItem/copy{0}", Path.GetExtension(info.FileName));
        }
Beispiel #3
0
        private async Task <ActionResult> BuildResponseFromMessage(Message message)
        {
            if (message == null)
            {
                return(new StatusCodeResult((int)System.Net.HttpStatusCode.NotFound));
            }


            var data = await FileRepository.Download(message.ContentId);

            var contentTypes = message.Headers.Where(x => x.Key == "Content-Type");

            var BadTypes = message.Headers.Where(x => x.Key == "Transfer-Encoding");

            foreach (var h in message.Headers.Except(contentTypes).Except(BadTypes))
            {
                Response.Headers.Add(new KeyValuePair <string, StringValues>(h.Key, new StringValues(h.Values.ToArray())));
            }

            return(File(data,
                        contentTypes.Any() ?
                        contentTypes.First().Values.First() :
                        "application/x-binary"));
        }