我正在尝试使用预先签名的 URL 在我的 s3 存储桶中上传一个文件,它运行良好并将数据成功上传到存储桶,但是,我上传的文件非常大,我需要能够显示进度条。我在 StackOverflow 和其他博客文章上尝试了许多可用的解决方案,但似乎没有任何帮助。
以下是使用预签名 URL 将数据上传到 s3 的代码片段。
object_name = 'DataSet.csv'
response = create_presigned_post("mybucket_name",object_name)
fields = response['fields']
with open(object_name, 'rb') as f:
files = {'file': (object_name, f)}
http_response = requests.post(response['url'], data=fields, files=files,stream=True)
print (http_response.status_code)
Run Code Online (Sandbox Code Playgroud)
它返回用于成功上传的204状态。
现在,我可以对此代码进行哪些更改以显示进度条。
PS 我尝试stream=True过请求不起作用。我曾尝试使用tqdm迭代响应,但在这种情况下也不起作用。