问题描述
我在 Mono 项目中使用 RestSharp 上传一些文件,我注意到当上传大文件时,内存会大幅增长.
I'm using RestSharp in a Mono project to upload some files and I have noticed that when a large file is uploaded, the memory grows substantially.
查看RestSharp 源代码我确实注意到 FileParameter 需要一个字节数组,这意味着它实际上是在将文件加载到内存中.
Looking at RestSharp source code I did notice that FileParameter expects a byte array, which means it is really loading the file into memory.
我做错了吗?RestSharp 有没有办法不这样做?我可能要上传非常大的文件,所以不能从内存中上传它们.
Am I doing something wrong? Is there a way for RestSharp not do this? I might be uploading really large files so, uploading them from memory is not an option.
欢迎提供任何帮助(包括告诉我使用 mono 上可用的另一个 HTTP 库).
Any help (including telling me to use another HTTP library available on mono) is welcome.
推荐答案
我找到后放弃了这一行,所以请求主体总是被加载到内存中,这很不幸,所以我构建了一个简单的解决方案来基于 这个问题 并从调试 Apache HttpClient 库.
And I gave up after I found this line, so request bodies are always loaded into memory, which is unfortunate, so I built a simple solution to do file uploads based on code from this question and from debugging the Apache HttpClient library.
如果有人感兴趣,可以这里获取源代码.
In case someone is interested, the source is available here.
这篇关于RestSharp 在上传时将整个文件加载到内存中.如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!