以下功能适用于将单个文件复制到Google云端存储.
#!/usr/bin/python3.5
import googleapiclient.discovery
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name, project):
storage_client = storage.Client(project=project)
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
现在我没有给出文件名,而是尝试输入目录名,upload_blob(‘mybucket’,’/ data / inputdata /’,’myapp / inputdata /’,’myapp’)
但后来我得到这个错误:
AttributeError: ‘str’ object has no attribute ‘read’
在调用函数blob.upload_from_file()复制目录时,是否需要提供任何其他参数?