首页 > 解决方案 > 使用预签名 URL PUT 方法上传文件不起作用 Python 请求

问题描述

我正在尝试读取驻留在 s3 存储桶内的文件并通过预签名的 url 将其上传到另一个 s3 存储桶。我尝试上传单个文件,效果很好。但是,如果我尝试上传存储桶中的文件列表,则无法上传数据。它始终将响应代码设为 200,但数据会上传到目标 s3 位置,尤其是大文件。

我的python代码如下。

import boto3
import requests
from io import BytesIO
 for file in file_list:#list of file names in the bucket
    pre_url=getPreSinedUrl()#for each file method will return a separate pre-signed url to upload file
    data_in_bytes = s3.get_object(Bucket="my-bucket", Key=file)['Body'].read()
    res = requests.put(pre_url, data=BytesIO(data_in_bytes), headers=my_header)
    print(res.status_code)

为什么没有上传 s3 中的文件有什么帮助?

标签: pythonamazon-s3python-requestsboto3put

解决方案


推荐阅读