使用boto在Python中上传文件到GCS

0 投票
1 回答
647 浏览
提问于 2025-05-01 16:32

我正在尝试通过boto将本地系统中的文件上传到云端的GCS(谷歌云存储)。但是在文件上传后,我收到了一个错误提示,内容是“你在Content-MD5或x-goog-hash中指定的MD5值与我们计算的值不匹配。”下面是我的代码。

def upload():
    bucket_name = 'bucketname'
    bucket = conn.get_bucket(bucket_name)
    fpic = Key(bucket)
    d='E:/Eclipse/workspace/Files'
    for filename in os.listdir(d):
        contents=d + '/' + filename
        fpic.key = 'my-files'+filename
        fpic.set_contents_from_filename(contents, {}, replace = True)
暂无标签

1 个回答

0

还有一种方法可以把本地的文件上传到GCS(谷歌云存储),那就是使用boto这个工具。你可以看看下面的链接 [1]。试试看,这个方法应该能顺利运行,不会出错。

[1] https://cloud.google.com/storage/docs/gspythonlibrary#credentials

撰写回答