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. 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.
Maybe this is an unsupported szenario?