If you're uploading the entire file in a single request then why do you use upload session when you can use the simple PUT
request?
url = https://graph.microsoft.com/v1.0/{user_id}/items/{parent_folder_ref_id}:/{filename}:/content
and "Content-Type": "text/plain"
header and in body simply put the file bytes
.
If for some reason I don't understand you have to use single-chunk upload session then:
Create upload session (you didn't specified any problems here so i'm not elaborating)
Get uploadUrl
from createUploadSession
response and send PUT
request with the following headers:
2.1 "Content-Length": str(file_size_in_bytes)
2.2 "Content-Range": "bytes 0-{file_size_in_bytes - 1}/{file_size_in_bytes}"
2.3 "Content-Type": "text/plain"
Pass the file bytes in body.
Note that in the PUT
request the body is not json
but simply bytes
(as specified by the content-type
header.
Also note that max chuck size is 4MB so if your file is larger than that, you will have to split into more than one chunks.
Goodlcuk
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…