Can not able to see a progress bar while uploading a file into google drive using python from memory buffer to a specific folder via google drive api #45681
Replies: 2 comments 5 replies
-
@PRITAMSLEARNINGACCOUNT You can Python Library ->tqdm to show the progress of the upload. Any questions GitHub related? Lmk thanks. |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaIoBaseDownload
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.http import MediaUploadProgress
from io import BytesIO
import zipfile
from googleapiclient.http import MediaUpload
from googleapiclient.http import MediaIoBaseUpload
import os.path
import pickle
CLIENT_ID = "My Client Id"
CLIENT_SECRET = "My Client Secret"
client_config = {
"installed": {
"client_id": "My Client Id",
"project_id": "My Project Name",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "My CLient Secret",
"redirect_uris": [
"http://localhost"
]
}
}
flow = InstalledAppFlow.from_client_config(
client_config=client_config, scopes=[
"https://www.googleapis.com/auth/drive",]
)
creds = flow.run_local_server(port=0)
Use the credentials to access the Google Drive API
drive_service = build('drive', 'v3', credentials=creds)
file_id = "1z5ckzwhuvhUMwgIg3MUfi177G17Za5Kq"
folder_id = "10BWu66m7vp3IyV7ORbl8i5nrBViT7_vW"
request = drive_service.files().get_media(fileId=file_id)
fh = BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print("Download %d%%." % int(status.progress() * 100))
fh.seek(0)
zip_file = zipfile.ZipFile(fh)
for file_name in zip_file.namelist():
# Get the file's metadata
file_metadata = {'name': file_name, 'parents': [folder_id]}
# Extract the file to a memory buffer
buf = BytesIO(zip_file.read(file_name))
# Create the file on Google Drive
media = MediaIoBaseUpload(
buf, mimetype='application/octet-stream', chunksize=1024*1024, resumable=True)
file = drive_service.files().create(
body=file_metadata, media_body=media, fields='id').execute()
zip_file.close()
This is My Code And Not Showing the progress bar of uploading the file please if anyone can able to solve this problem give me the solution
Beta Was this translation helpful? Give feedback.
All reactions