有没有办法在使用 gdrive API 将文件上传到 google 驱动器时重命名文件?
Is there a way to rename a file while uploading it to google drive using gdrive API?
我正在 google 驱动器上自动上传文件(使用 google 驱动器 API)。
我想在上传文件时重命名(因为它的标签本来就是文件的完整路径目录,很长)。
我正在使用此功能将文件上传到 gdrive:
def upload_file_gdrive(file_path, base_currency, gdrive_path_id):
# Authentication (automated using the config files)
# The config files should be dropped in the current working directory
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
# Upload file on gdrive
print('Uploading the market data on google drive')
gfile = drive.CreateFile({'parents': [{'id': gdrive_path_id}]})
gfile.SetContentFile(file_path)
gfile.Upload() # Upload the file.
print('Market data upload on google drive successful')
我们有办法在上传文件时重命名文件吗?
干杯
创建文件实际上分两部分完成,发送描述文件的元数据,然后发送文件的实际内容。
您只需在元数据中提供即可更改名称。
gfile = drive.CreateFile({'parents': [{'id': gdrive_path_id}]})
gfile['title'] = 'HelloWorld.txt' # Change title of the file.
gfile.SetContentFile(file_path)
gfile.Upload() # Upload the file.
我正在 google 驱动器上自动上传文件(使用 google 驱动器 API)。
我想在上传文件时重命名(因为它的标签本来就是文件的完整路径目录,很长)。
我正在使用此功能将文件上传到 gdrive:
def upload_file_gdrive(file_path, base_currency, gdrive_path_id):
# Authentication (automated using the config files)
# The config files should be dropped in the current working directory
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
# Upload file on gdrive
print('Uploading the market data on google drive')
gfile = drive.CreateFile({'parents': [{'id': gdrive_path_id}]})
gfile.SetContentFile(file_path)
gfile.Upload() # Upload the file.
print('Market data upload on google drive successful')
我们有办法在上传文件时重命名文件吗?
干杯
创建文件实际上分两部分完成,发送描述文件的元数据,然后发送文件的实际内容。
您只需在元数据中提供即可更改名称。
gfile = drive.CreateFile({'parents': [{'id': gdrive_path_id}]})
gfile['title'] = 'HelloWorld.txt' # Change title of the file.
gfile.SetContentFile(file_path)
gfile.Upload() # Upload the file.