Spaces:
Sleeping
Sleeping
def upload_to_drive(service, file_name, folder_id, content):
Browse files
app.py
CHANGED
|
@@ -15,6 +15,8 @@ import os
|
|
| 15 |
from google.oauth2 import service_account
|
| 16 |
from googleapiclient.discovery import build
|
| 17 |
from googleapiclient.http import MediaFileUpload
|
|
|
|
|
|
|
| 18 |
import io
|
| 19 |
|
| 20 |
|
|
@@ -83,15 +85,6 @@ def check_file_exists(service, folder_name, file_name):
|
|
| 83 |
files = response.get('files', [])
|
| 84 |
return len(files) > 0, files[0]['id'] if files else None
|
| 85 |
|
| 86 |
-
# 上传文件到Google Drive
|
| 87 |
-
def upload_to_drive(service, file_name, folder_id, content):
|
| 88 |
-
file_metadata = {
|
| 89 |
-
'name': file_name,
|
| 90 |
-
'parents': [folder_id]
|
| 91 |
-
}
|
| 92 |
-
media = MediaIoBaseUpload(io.BytesIO(content.encode()), mimetype='text/plain')
|
| 93 |
-
file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
|
| 94 |
-
return file.get('id')
|
| 95 |
|
| 96 |
def upload_to_drive(service, file_name, folder_id, content):
|
| 97 |
print("上传文本内容到Google Drive指定的文件夹中")
|
|
|
|
| 15 |
from google.oauth2 import service_account
|
| 16 |
from googleapiclient.discovery import build
|
| 17 |
from googleapiclient.http import MediaFileUpload
|
| 18 |
+
from googleapiclient.http import MediaIoBaseUpload
|
| 19 |
+
|
| 20 |
import io
|
| 21 |
|
| 22 |
|
|
|
|
| 85 |
files = response.get('files', [])
|
| 86 |
return len(files) > 0, files[0]['id'] if files else None
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def upload_to_drive(service, file_name, folder_id, content):
|
| 90 |
print("上传文本内容到Google Drive指定的文件夹中")
|