I have been at this for a week and it's getting frustrating. On the final upload request, I get the error "Invalid Content-Range header." All other chunk uploads are successful, only the last one gets this error. How do I set the "Content-Range" header for uploading file chunks using the MS Graph API?
This is my latest code:
using (var fileStream = File.OpenRead(attachmentLocation))
{
var buffer = new byte[1000 * 1024];
int bytesRead;
long totalBytesUploaded = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
var requestEmail = new RestRequest(upload_url, Method.Put);
requestEmail.AddHeader("Content-Type", "application/octet-stream");
//requestEmail.AddHeader("Content-Length", bytesRead);
requestEmail.AddHeader("Content-Range", $"bytes {totalBytesUploaded}-{totalBytesUploaded + bytesRead - 1}/{fileStream.Length}");
requestEmail.AddBody(buffer, ContentType.Json);
var response = client.Execute(requestEmail);
totalBytesUploaded += bytesRead;
}
}