私は2ビットのコードを持っています。 zipファイルをアップロードするサーバーとアップロードをドライブに保存するサーバー。私の問題は、Windows 7のデフォルトの圧縮プログラムでは正常に開くzipファイルをアップロードすることですが、Webサーバーから開こうとするとエラーが表示されなくなりました。Win 7のZipプログラムでHTTP経由でZipファイルを公開しない
Windowsは開けませんフォルダ。圧縮されたzipフォルダ「blah」は無効です。
注1:このファイルは、WinRarまたは他のzipプログラムで完全に正常に開きます。
注2:元のファイルとサーバー上のファイルがディスク上に正確に同じ大きさですが、サーバーの1の大きさは
200ishバイト大きいここでアップロードジッパーのためのコードは次のとおりです。
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));
}
:ここ
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ページのページ・ロード中に存在する)を保存するサーバ上のコードであります
これが壊れている可能性がある場所として、考えられることや提案がありがとうございます。私はおそらくzipファイルと一緒にいくつかの他のランダムなものを保存しています。
UPDATE 1:
私はメモ帳で、サーバーのzipファイルを開くと、それは
-----------------------8cd8d0e69a0670b Content-Disposition: form-data; name="file"; filename="filename.zip" Content-Type: application/octet-stream
が含まれているので、私の質問は、ヘッダ情報をキャプチャすることなく、zipファイルを保存する方法です。
ええ、あなたが投稿したのと同じように答えを見つけました。 Request.Files [0] .SaveAs(zipPath);それをやった。ありがとう! –