Last active
April 30, 2019 20:32
-
-
Save MareArts/974a52d2d04ebe730edf08be2e68421d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://www.cvlecture.marearts.com/forum/computer-vision-forum/upload-file-to-google-drive-using-python-writing | |
from googleapiclient.discovery import build | |
from httplib2 import Http | |
from oauth2client import file, client, tools | |
try : | |
import argparse | |
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() | |
except ImportError: | |
flags = None | |
SCOPES = 'https://www.googleapis.com/auth/drive.file' | |
store = file.Storage('storage.json') | |
creds = store.get() | |
if not creds or creds.invalid: | |
print("make new storage data file ") | |
flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES) | |
creds = tools.run_flow(flow, store, flags) \ | |
if flags else tools.run(flow, store) | |
DRIVE = build('drive', 'v3', http=creds.authorize(Http())) | |
FILES = ( | |
('marearts.png'), | |
) | |
for file_title in FILES : | |
file_name = file_title | |
metadata = {'name': file_name, | |
'mimeType': None | |
} | |
res = DRIVE.files().create(body=metadata, media_body=file_name).execute() | |
if res: | |
print('Uploaded "%s" (%s)' % (file_name, res['mimeType'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.cvlecture.marearts.com/forum/computer-vision-forum/upload-file-to-google-drive-using-python-writing