小编Man*_*nan的帖子

没有存储桶策略的 s3 预签名 url 不起作用

这是我尝试过的。

拉姆达代码:

import uuid

import boto3


def lambda_handler(event, context):
    # Get the service client.
    s3 = boto3.client('s3')

    # Generate a random S3 key name
    upload_key = uuid.uuid4().hex

    # Generate the presigned URL for put requests
    presigned_url = s3.generate_presigned_url(
        ClientMethod='put_object',
        Params={
            'Bucket': 'test',
            'Key': upload_key,
            'ContentType': 'image/png',
            'ACL': 'public-read'
        }
    )

    # Return the presigned URL
    return {
        "upload_url": presigned_url
    }
Run Code Online (Sandbox Code Playgroud)

s3 存储桶的 CORS 策略

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <ExposeHeader>ETag</ExposeHeader>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration> …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services

2
推荐指数
1
解决办法
5514
查看次数

标签 统计

amazon-s3 ×1

amazon-web-services ×1