RestSharp 在上传时将整个文件加载到内存中.如何避免?

RestSharp is loading the whole file into memory when uploading. How to avoid it?(RestSharp 在上传时将整个文件加载到内存中.如何避免?)
本文介绍了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 在上传时将整个文件加载到内存中.如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)