RestSharp loads the entire file into memory at boot. How to avoid this?

I use RestSharp in the Mono project to download some files, and I noticed that when loading a large file, the memory increases significantly.

Looking at the RestSharp Source Code I noticed that FileParameter expects an array of bytes, which means that it really loads the file into memory.

Am I doing something wrong? Is there a way for RestSharp not to do this? I can upload really large files, so loading them from memory is not an option.

Any help (including pointing out to use a different HTTP library available in mono) is appreciated.

+7
source share
2 answers

And I gave up after I found this line , so the request bodies are always loaded into memory, which is unsuccessful, so I built a simple solution for downloading files based on the code from this question and debugging the Apache HttpClient library .

If anyone is interested, the source is available here .

+4
source

Use overload AddFile(name, writer, filename) .

For the writer parameter, pass an Action<Stream> , which is written directly to the request body stream. Do not block the stream.

Here is an example to write to a stream .

+4
source

All Articles