Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @handle_upload_errors
- def upload_file(
- local_file_path,
- google_location="", # folder id on Google Drive or name from google_folders dict
- file_name=""
- ):
- if not file_name:
- file_name = local_file_path
- p(f"File {local_file_path} uploading to folder {google_location}")
- if google_location in google_folders:
- google_location = google_folders[google_location]
- file_metadata = {
- 'name': file_name,
- 'parents': [google_location]
- }
- media = googleapiclient.http.MediaFileUpload(local_file_path, resumable=True)
- """
- resumable allows uploading files over 5MB.
- """
- uploaded_file_properties = service.files().create(
- body=file_metadata,
- media_body=media,
- fields='id, parents', # to retrun an id of uploaded file
- ).execute()
- p(f"File {file_name} uploaded")
- return uploaded_file_properties
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement