Python &引用;成功“行动”和“重定向”;在基于浏览器的向S3上传文件的身份验证请求中不起作用
我是aws S3新手,我正在尝试构建一个web应用程序,允许用户使用boto3直接将文件上传到S3 用户首先将请求发送到我自己的服务器(例如),我的web应用程序(用python Flask编写)有一个表单,允许用户上传文件。然后,该应用程序将允许用户使用经过身份验证的请求(AWS身份验证签名版本4)将文件直接上载到S3 我基本上遵循了这个URL()中的步骤。 请注意,我没有使用Heroku构建我的web服务器。我在另一家软管公司有自己的服务器 因此,当我没有在字段和条件中指定“success\u action\u redirect”时,代码就会工作。 如果我想将用户重定向到我自己的服务器,如果上传成功。代码不起作用。错误消息如下所示Python &引用;成功“行动”和“重定向”;在基于浏览器的向S3上传文件的身份验证请求中不起作用,python,amazon-s3,flask,Python,Amazon S3,Flask,我是aws S3新手,我正在尝试构建一个web应用程序,允许用户使用boto3直接将文件上传到S3 用户首先将请求发送到我自己的服务器(例如),我的web应用程序(用python Flask编写)有一个表单,允许用户上传文件。然后,该应用程序将允许用户使用经过身份验证的请求(AWS身份验证签名版本4)将文件直接上载到S3 我基本上遵循了这个URL()中的步骤。 请注意,我没有使用Heroku构建我的web服务器。我在另一家软管公司有自己的服务器 因此,当我没有在字段和条件中指定“success\
"XMLHttpRequest cannot load https://test1.s3.amazonaws.com/. Cross-origin redirection denied by Cross-Origin Resource Sharing policy."
这是我的python代码块
@app.route('/sign_s3/')
def sign_s3():
file_name = 'testfd/' + request.args.get('file_name')
file_type = request.args.get('file_type')
s3 = boto3.client("s3", aws_access_key_id=AWS_ID,aws_secret_access_key=AWS_KEY)
presigned_post = s3.generate_presigned_post(Bucket = AWS_BUCKET, \
Key = file_name,Fields = {"acl": "public-read", "Content-Type": file_type, "success_action_redirect":"https://example.com" }, \
Conditions = [{"acl": "public-read"},{"Content-Type": file_type}, { "success_action_redirect": "https://example.com"}],\
ExpiresIn = 3600)
result_json = json.dumps({'data': presigned_post,\
'url': 'https://%s.s3.amazonaws.com/%s' % (AWS_BUCKET, file_name)})
return result_json
此外,这里是CORS配置
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin> https://example.com </AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
{"success_action_redirect": "https://example.com"} or {"success_action_redirect": "https://example.com/uploadOK.html"}