Python - 将文件上传到云存储

Python - Upload File to Cloud Storage

https://cloud.google.com/storage/docs/json_api/v1/json-api-python-samples

使用上面的示例,我能够将文件上传到存储桶。但是我无法将其上传到存储桶中的文件夹。

错误:"Invalid bucket name:"

感谢任何帮助!

def upload_object(bucket, filename, readers, owners):
    service = create_service()

    # This is the request body as specified:
    # http://g.co/cloud/storage/docs/json_api/v1/objects/insert#request
    body = {
        'name': 'foldername/' + filename,
    }

添加 'foldername/' + 文件名。

这会将其定向到正确的位置。