0

I am creating a flask application in python that needs to move local files to google drive using the Pydrive library and Google Drive API. All goes well until I upload the file and then I get the following error:

pydrive.files.ApiRequestError: <HttpError 404 when requesting None returned "File not found: 2". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'File not found: 2', 'locationType': 'other', 'location': 'file'}]">

My code is as follows.

gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
if file_ext == ".jpg":
    mimeType = "image/jpeg"
elif file_ext == ".png":
    mimeType = "image/png"
elif file_ext == ".gif":
    mimeType = "image/gif"
elif file_ext == ".mp4":
    mimeType = "video/mp4"
elif file_ext == ".mp3":
    mimeType = "audio/mpeg"
elif file_ext == ".wav":
    mimeType = "audio/wav"
elif file_ext == ".bmp":
    mimeType = "image/bmp"
elif file_ext == ".docx":
    mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
elif file_ext == ".txt":
    mimeType = "text/plain"
elif file_ext == ".MOV":
    mimeType = "video/quicktime"
elif file_ext == ".pdf":
    mimeType = "application/pdf"
file1 = drive.CreateFile({"mimeType": mimeType, "parents": [{"kind": "drive#fileLink", "id": uniqueID}]}) #uniqueID is defined earlier on based on the fileID in my database
file1.SetContentFile(filename)
file1.Upload()

Any help would be greatly appreciated as the project is for college and I am not the most experienced in flask, let alone PyDrive!

Thanks :)

1 Answers1

0

Turns out the fix was simple, I wasn't providing a correct fileID in the line file1 = drive.CreateFile({"mimeType": mimeType, "parents": [{"kind": "drive#fileLink", "id": uniqueID}]}), I was creating my own fileID as uniqueID thinking this was just an ID assigned to the file, it actually is the ID that refers to the folder you want to upload to, you can get this from the URL of your google drive folder. The correct line is file1 = drive.CreateFile({"mimeType": mimeType, "parents": [{"id": "11Ys4m6_HReCVfaZvpm4n84IMXjOX42yX"}]}), hope that helps anyone else with the same issue!