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 在上传时将整个文件加载到内存中.如何避免?
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30