I am trying to upload a large attachment file to send via mail.
As this link outlook-large-attachments suggests, I created a draft message with all the necessary parameters and started the upload session which gave me as a response the opaque url, expiration time and so on (til here, everything works fine). The next step where I have to use PUT iteratively to upload parts of the mail, gives me no response and the code keeps running. I tried using POST or GET instead of PUT to see if anything changes & changing the opaque url, but the same behavior continues.
I searched the internet endlessly but could not find someone with a similar problem. Can anyone help me?
#create draft
payload=json.dumps({
"subject":subject,
"importance":"Low",
"body":{
"contentType":"Text",
"content":content
},
"toRecipients":setup_recipients(recipients)
})
mail_data_draft = requests.post(url=ms_graph_endpoint_draft, data=payload, headers={'Authorization': 'Bearer ' + result['access_token'], 'Content-Type': 'application/json'})
message_id=json.loads(mail_data_draft.text)["id"]
#creating upload session with message id
upload_session_endpoint="https://graph.microsoft.com/v1.0/users/" + email_account +"/messages/"+message_id+"/attachments/createUploadSession"
up_session_payload= json.dumps({
"AttachmentItem":{
"attachmentType":"file",
"name":"fileName",
"size": contentSize,
}
})
upload_session_info= requests.post(url=upload_session_endpoint, data=up_session_payload, headers={'Authorization': 'Bearer ' + result['access_token'], 'Content-Type': 'application/json'})
opaque_url =json.loads(upload_session_info.text)["uploadUrl"]
next_expected_range=json.loads(upload_session_info.text)["nextExpectedRanges"][0]
#####################################################################Tested till here
#uploading attachment
#problem
print("start")
upload_things = requests.put(url=json.loads(upload_session_info.text)["uploadUrl"],headers={'Content-Type':'application/octet-stream','Content-Length':'327680','Content-Range': 'bytes 0-327679/'+str(contentSize)})
#keeps running
#iteration
print(upload_things.text)
print("done")
##The last two lines are not processed as code gets stuck in requests.put() -> terminal prints : start only