簡體   English   中英

從app_data文件夾下載文件,但格式已損壞

[英]File gets downloaded from app_data folder, but in the corrupted format

我的Web應用程序將文件(.png,.bmp,.jpg,.jpeg,.jpe,.jfif,.gif,.tif,.tiff,.doc,.docx,.pdf,.xls,.xlsx)存儲app_data / upload文件夾。 它像存儲在本地系統上一樣存儲在實時服務器上。 但是,當嘗試下載時,它以相同的文件大小但格式損壞被下載。

這是從實時服務器下載文件的代碼。

string strURL = "~/App_Data/Upload/" + fileRepository.FileName;
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.ContentType = "application/octet-stream";
response.AppendHeader("Content-Disposition", "attachment;filename=\"" + fileRepository.FileName + "\"");
byte[] data = req.DownloadData(Server.MapPath(strURL));
response.BinaryWrite(data);
response.TransmitFile(Server.MapPath(strURL));
FileRespository.DownloadCount(Convert.ToString(_fileID));
response.End();

下載Word文件時,請查找附件的圖像。 請幫幫我。 下載Word文件時,請查找附件的圖像。

讀取文件作為塊/緩沖區,而不是傳輸文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM