我正在尝试从我的 Fiddle 调试器将视频文件 .mov 上传到远程 Web 服务以测试该服务,但存储在磁盘上的文件损坏了?有什么建议么?
请求标头
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
{
}