Spaces:
Running
Running
def copy_file_from_drive_to_gcs(drive_service, gcs_client, file_id, bucket_name, gcs_destination_path):
Browse files
app.py
CHANGED
@@ -126,10 +126,20 @@ def copy_all_files_from_drive_to_gcs(drive_service, gcs_client, drive_folder_id,
|
|
126 |
|
127 |
def copy_file_from_drive_to_gcs(drive_service, gcs_client, file_id, bucket_name, gcs_destination_path):
|
128 |
# Download file content from Drive
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
# Upload file content to GCS
|
131 |
-
|
132 |
-
|
|
|
|
|
133 |
|
134 |
# # ====drive====初始化Google Drive服务
|
135 |
def init_drive_service():
|
|
|
126 |
|
127 |
def copy_file_from_drive_to_gcs(drive_service, gcs_client, file_id, bucket_name, gcs_destination_path):
|
128 |
# Download file content from Drive
|
129 |
+
request = drive_service.files().get_media(fileId=file_id)
|
130 |
+
fh = io.BytesIO()
|
131 |
+
downloader = MediaIoBaseDownload(fh, request)
|
132 |
+
done = False
|
133 |
+
while not done:
|
134 |
+
status, done = downloader.next_chunk()
|
135 |
+
fh.seek(0)
|
136 |
+
file_content = fh.getvalue()
|
137 |
+
|
138 |
# Upload file content to GCS
|
139 |
+
bucket = gcs_client.bucket(bucket_name)
|
140 |
+
blob = bucket.blob(gcs_destination_path)
|
141 |
+
blob.upload_from_string(file_content)
|
142 |
+
print(f"File {file_id} copied to GCS at {gcs_destination_path}.")
|
143 |
|
144 |
# # ====drive====初始化Google Drive服务
|
145 |
def init_drive_service():
|