簡體   English   中英

通過HTTP發布Zip文件不再在Win 7 Zip程序中打開

[英]Posting Zip Files over HTTP No Longer Opening in Win 7 Zip Program

我有兩位代碼。 上載一個zip文件的服務器和一個將上載的文件保存到驅動器的服務器。 我的問題是我上傳了一個zip文件,該文件在Windows 7的默認zipping程序中可以正常打開,但是當我嘗試從網絡服務器打開它時,它也被發布了,它也不會再出現錯誤:

Windows無法打開該文件夾。 壓縮的壓縮文件夾“ blah”無效。

注意1:該文件在WinRar或其他zip程序中完全可以正常打開。

注意2:原始文件和服務器上的文件在磁盤上的大小完全相同,但是其中一個服務器的大小大了200ish字節

以下是上傳zip的代碼:

        public static String UploadFile(String url, String filePath)
        {
            if (!File.Exists(filePath))
                throw new FileNotFoundException();

            try
            {
                using (var client = new WebClient())
                {
                    byte[] result = client.UploadFile(url, filePath);

                    UTF8Encoding enc = new UTF8Encoding();
                    string response = enc.GetString(result);

                    return response;
                }
            }
            catch (WebException webException)
            {
                HttpWebResponse httpWebResponse = webException.Response as HttpWebResponse;

                return (httpWebResponse == null) ? webException.Message : httpWebResponse.StatusCode.ToString();
            }
        }

這是服務器上保存傳入文件的代碼(存在於.NET C#aspx頁面的頁面加載中):

        private void SaveZipFile()
        {
            string fileName;
            string zipPath;

            fileName = GenerateFileName();

            zipPath = _hhDescriptor.GetDirectory(path => Server.MapPath(("./" + _serviceName + "\\" + path)) + "\\" + fileName + ".zip");        


        if (!Directory.Exists(zipPath))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(zipPath));
        }

        Request.SaveAs(zipPath, false);

        logger.Trace(string.Format("ManualUpload: Successfully saved uploaded zip file to {0}", zipPath));
    }

任何想法/或建議,可能會打破的地方,將不勝感激! 我可能會隨zip文件一起保存其他一些隨機內容。

更新1:

當我在記事本中打開服務器的zip文件時,它包含

----------------------- 8cd8d0e69a0670b內容處置:form-data; NAME = “文件”; filename =“ filename.zip”內容類型:application / octet-stream

所以我的問題是如何在不捕獲標題信息的情況下保存zip。

我相信問題出在使用HttpRequest.SaveAs 我懷疑這會保存整個請求,包括HTTP標頭。 在二進制文件編輯器中查看文件,我懷疑您會在一開始就找到標題。

使用HttpRequest.Files獲取作為請求的一部分上傳的文件,並使用HttpPostedFile.SaveAs將文件保存到磁盤。

您正在編寫整個請求,其中可能包含一些Multipart MIME分隔符。 我認為您需要使用Request.Files

暫無
暫無

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

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