[英]Posting a large file via HTTP/REST in C# without loading file into memory
I would like to upload a large file as a standard multipart post message. 我想上传一个大文件作为标准的多部分帖子消息。 All the C# examples I see however typically use byte arrays (which require the entire file be loaded into the contents of memory).
但是,我看到的所有C#示例通常都使用字节数组(要求将整个文件加载到内存的内容中)。 I can see that there is a StreamContent type but it isn't clear to me that embedding that in a multi part upload would stream the request with minimal memory impact.
我可以看到有一个StreamContent类型,但我不清楚将其嵌入多部分上传中将以最小的内存影响流式传输请求。
Here's coding wise what I'm thinking. 这是我在思考的明智编码。
using (HttpRequestMessage request = new HttpRequestMessage (HttpMethod.Post, uploadURL)) {
MultipartFormDataContent multiPartContent = new MultipartFormDataContent ("----Abs23AawqrrqTbbSWpppo8--");
StreamContent streamContent = new StreamContent (new FileStream(path, FileMode.Open));
streamContent.Headers.Add ("Content-Type", "video/mov");
streamContent.Headers.Add ("Content-Length", new FileInfo(path).Length.ToString() );
multiPartContent.Add (streamContent, "bigMovie.mov", "bigMovie.mov");
request.Content = multiPartContent;
using (HttpResponseMessage response = await client.SendAsync (request)) {
// check status code
}
}
Is this the correct way to handle a multi part upload for a large file that would be too big to load into memory? 对于处理太大而无法加载到内存的大文件,这是处理多部分上传的正确方法吗?
Doing it FTP way would be more efficient. 以FTP方式进行操作会更有效。 FTP code also supports resume mode.
FTP代码还支持恢复模式。 And is more efficient protocol for file uplaod
并且是用于文件更新的更有效协议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.