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 在上传时将整个文件加载到内存中.如何避免?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
