I'm trying to upload a pdf file created on my computer with path output_pdfs/<pdf-name>.pdf
. I'm using the id
of the parent folder of where I want to upload the files to in my code. I'm getting an HttpError 404 "File Not Found .", referring to the parent ID (parent folder). I've read here I can get the parentID by using the childID but that doesn't work as I want to create a sub-folder (child) because it might not exist yet.
Steps I've done:
- Shared the Google Drive folder with the service account and set it to "Content Manager"
- Added auth scopes for my service account in my python code
"https://www.googleapis.com/auth/drive"
- Ensured that my gcloud credentials are set correctly,
gcloud auth list
shows I'm using the same credentials that I shared the sheet with.
def deliver_to_google_drive(output_pdf, creds, parentFolderID, folderToCreate):
drive_service = build('drive', 'v3', credentials=creds)
file_metadata = {
'parents':[parentFolderID],
'name': output_pdf
}
media = MediaFileUpload(output_pdf, mimetype='application/pdf',resumable=True)
file = drive_service.files().create(body=file_metadata, """<-- 404 error here"""
media_body=media,
fields='id').execute()
print('File ID: %s' % file.get('id'))
file.Upload()
Thank you.