I am running into an issue uploading files to an upload session using v1.0 Microsoft Graph API. My steps:
Here is the error I am receiving:
{
"error":
{
"code":"invalidRequest",
"message":"The Content-Range header is missing or malformed."
}
}
I have tried using the following formats and I still receive the same error.
"bytes 0-100/100"
"0-100/100"
"0-100"
I am following this article from Mircosoft https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_createuploadsession
Here is my function that uploads to the uploadUrl retreived from creating the upload session
public uploadToSession(file: HTMLInputElement, session: any, fileData: any) {
var headers = new Headers();
headers.append('Content-Length', fileData.length); //(ie: "100")
headers.append('Content-Range', fileData.range); //(ie: "bytes 0-100/100")
this.http.put(session.uploadUrl, { headers })
.subscribe(
(res: Response) => console.log(res),
error => console.log(error)
);
}
Any help is much appreciated! Thanks in advance.
The Content-Range
header has the following format:
Content-Range: bytes <startindex>-<endindex>/<totallength>
Your issue appears to be a mixing of indexes (0-based) and lengths (1-based). For a 100-byte file your header would need to look like:
Content-Range: bytes 0-99/100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With