I'm struggling to correctly upload a file to Google Drive through their API. I'm using Python and I'm aware that there is a client library for Google's API. Here is what I currently have. When running the below code, an empty untitled document is created in Google Drive and it's not in the correct directory, root/level_1
. I'm not sure what I'm doing wrong with the data
and files
object. Is there anything that stands out from the code?
Here are the docs that I was following.
import json
import requests
url = "https://www.googleapis.com/upload/drive/v2/files?access_token=ACCESS_TOKEN&uploadType=multipart"
files = {"file": requests.get("image_url").content}
data = {
"title": "image_url.jpg",
"parents": ["root", "level_1"]
}
response = requests.post(url, data=json.dumps(data), files=files)
# json.loads(response.text)["title"] = "Untitled"
return response