forked from hp0303/Colab_image_uloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploader.py
More file actions
32 lines (24 loc) · 894 Bytes
/
uploader.py
File metadata and controls
32 lines (24 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from googleapiclient.discovery import build
from google.oauth2 import service_account
scopes = ['https://www.googleapis.com/auth/drive']
service_account_file = "image-upload-423409-6c68e51e6af7.json"
folder_id = "1sIaAiwBVWALcZM4O4hwDDEkHNuxsXJXA"
file_id = ""
def authenticate():
creds = service_account.Credentials.from_service_account_file(service_account_file, scopes=scopes)
return creds
def upload_file(file_path):
global file_id
creds = authenticate()
service = build('drive', 'v3', credentials=creds)
file_metadata = {
'name': file_path,
'parents': [folder_id]
}
file = service.files().create(
body=file_metadata,
media_body=file_path
).execute()
file_id = file.get("id")
upload_file("shutterstock_2205178589-1-1.png")
print(f"<center>\n<img src=https://drive.google.com/uc?id={file_id} /><br>\n</center>")