I am making a C# console application to encrypt and upload files to Backblaze B2 backup. I am using HttpWebRequest to upload files using their API, however, I get an IOException "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host."
from stream.Write
when uploading anything bigger than 4MB. I have to use a HTTP POST request as per the B2 API, so is there a way to get past .Net's 4MB limit?
My relevant code is
internal void UploadFile(FileInfo f, string sha1) {
HttpWebRequest webRequest = WebRequest.CreateHttp(this.uploadUrl);
webRequest.Method = "POST";
webRequest.Headers.Add("Authorization", this.uploadAuthorizationToken);
webRequest.Headers.Add("X-Bz-File-Name", f.Name);
webRequest.Headers.Add("X-Bz-Content-Sha1", sha1);
webRequest.ContentType = "application/octet-stream";
webRequest.ContentLength = f.Length;
byte[] bytes = File.ReadAllBytes(f.FullName);
using (var stream = webRequest.GetRequestStream()) {
stream.Write(bytes, 0, bytes.Length); //IOException occurs here
stream.Close();
}
WebResponse response = (HttpWebResponse)webRequest.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close();
Console.WriteLine("b2_upload_file:\n" + responseString);
}
And the documentation for b2_upload_file https://www.backblaze.com/b2/docs/b2_upload_file.html