This question is not answered yet in Stack Overflow and it's not duplicated
I have a code exactly like this, try to upload files with RestSharp library.
Problem :
But the problem is upload files fill the memory (RAM) and it's bad or got error on large files.
var client = new RestClient("https://example.com/api/");
var request = new RestRequest("file/upload", Method.POST);
string filePath = @"C:\LargeFile.mkv";
client.ConfigureWebRequest(x => x.AllowWriteStreamBuffering = true);
request.AddHeader("Content-Type", "multipart/form-data");
request.AddParameter("access_token", "exampleToken");
request.AddFileBytes("upload_file", File.ReadAllBytes(filePath), Path.GetFileName(filePath), MimeMapping.GetMimeMapping(filePath));
client.ExecuteAsync(request, response =>
{
Console.WriteLine(response.Content);
});
Note: I don't find a working way to do this without filling RAM, I know that it must use stream types or byte arrays, but I can't do it.