Per documentation, I remember this -
your app must ensure the total file size specified in the Content-Range header is the same for all requests. If a byte range declares a different file size, the request will fail.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'll refer to my original StackOverflow post, you can find here: https://stackoverflow.com/questions/64772346
I'm developing a node service, that pushes file to SharePoint online.
We are using the official Graph SDK for JavaScript (..and Types).
so far - everything's fine, but if the folder contains a file that has 0-length, I can not find a way to push these files to the drive.
If I try to use the MicrosoftGraph.LargeFileUploadTask
JavaScript Class or the OneDriveLargeFileUploadTask
the upload doesn't even start, because the formatting of the "Content-Length" header in uploadSlice()
fails.
We can skip the class's code and just upload an empty slice by ourself (all code only applies to empty files):
uploadedFile = await client
.api(uploadSession.url)
.headers({
"Content-Length": `0`,
"Content-Range": `bytes 0-0/0`,
})
.put(file); //file is an empty Buffer
Results in: Error: The Content-Range header is missing or malformed
I've tried to commit the empty file without uploading a slice: according to https://learn.microsoft.com/de-de/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#completing-a-file (I've explictly set deferCommit=true
for the upload session)
After the final byte range of the file is PUT to the upload URL, send a final POST request to the upload URL with zero-length content (currently only supported on OneDrive for Business and SharePoint).
uploadedFile = await client.api(requestUrl)
.headers({
"Content-Length": `0`,
})
.post(null);
No Luck, this is the response: SharePoint / Graph expects the missing bytes of unkown lenght, I think:
{
"@odata.context":"...",
"expirationDateTime":"2020-11-10T16:04:31.594Z",
"nextExpectedRanges":["0-"],
"uploadUrl":"..."
}
The file is not present.
I can not find any documentation on how to handle empty files with Microsoft Graph / SharePoint. I've thought about creating an empty file like using touch
online, instead of uploading it, but I can not find a way to do that either.
So I'm searching for an official source that can tell me wether 0-byte files in SharePoint Online are generally supported or not. And if yes - under which circumstances.
Thank you!
Per documentation, I remember this -
your app must ensure the total file size specified in the Content-Range header is the same for all requests. If a byte range declares a different file size, the request will fail.