RestSharp is loading the whole file into memory when uploading. How to avoid it?(RestSharp 在上传时将整个文件加载到内存中.如何避免?)
问题描述
我在 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 在上传时将整个文件加载到内存中.如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:RestSharp 在上传时将整个文件加载到内存中.如何避免?
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01