我想從我的小提琴調試器上傳視頻文件.mov到遠程Web服務來測試服務,但存儲在磁盤上的文件出來是腐敗?有什麼建議麼?二進制上載WCF腐敗.mov文件
請求頭
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: localhost:2487
Content-Length: 2113228
請求體
---------------------------acebdf13572468
Content-Disposition: form-data; name="IMG_0888.MOV"; filename="IMG_0888.MOV"
Content-Type: video/quicktime
<@INCLUDE *C:\Users\Amrit\Desktop\IMG_0888.MOV*@>
---------------------------acebdf13572468--
C#代碼
FileStream fs = null;
string UniqueId = this.GenerateUID();
_fileDirectory = System.IO.Path.Combine(Constants._VideosDirectory,author_id);
if (!Directory.Exists(_fileDirectory))
{
Directory.CreateDirectory(_fileDirectory);
}
string file = Path.Combine(_fileDirectory, "test.mov");
// string filePath = Path.Combine(uploadFolder, request.FileName);
try
{
using (FileStream targetStream = new FileStream(file, FileMode.Create,
FileAccess.Write, FileShare.None))
{
//read from the input stream in 65000 byte chunks
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = request.Read(buffer, 0, bufferLen)) > 0)
{
// save to output stream
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
return "done";
//sourceStream.Close();
}
}
catch (Exception)
{
return "fail";
}
finally
{
}
很可能是因爲您將整個請求保存到磁盤 - 您需要查看請求並獲取實際的文件內容。 – 2012-04-25 15:29:34
謝謝@AndrasZoltan – Amrit 2012-04-26 15:34:48