I have a quite large file that I am trying to upload to google drive using the API. I am trying to do it with a sample image for learning purposes. Uploading the image as a multiplart upload or a single file upload works without hesitation, but the moment I try to do it using the resumable upload endpoint, the code gives me a error as:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: image/jpeg"
}
],
"code": 400,
"message": "Unsupported content with type: image/jpeg"
}
}
The code that I am using is as follows:
import requests
import os
filesize = os.path.getsize('./photo.jpeg')
print("File size is: ", filesize)
headers = {"Authorization" : "Bearer "+"<MY API KEY HERE>",
"Content-Length": str(filesize),
"Content-Type": "image/jpeg"}
params = {
"name": "sample.png",
"parents": ['1CxrbEfy5y3ZyBVF6k2IFIuOk_Z0wjZAo']
}
files = {
'data': ('metadata', json.dumps(params), 'image/jpeg'),
'file': open('./photo.jpeg', 'rb')
}
r = requests.post(
"https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable",
headers = headers,
files = files
)
print(r.text)
Please help.