首页 > 解决方案 > 通过 boto3 创建 AWS S3 预签名 url 时如何设置文件的限制大小

问题描述

我想创建 S3 预签名 url 并以特定限制文件大小提供给客户端,例如最小文件大小为 200kib,最大文件大小为 1024 kib

我使用函数创建create_presigned_url

create_presigned_url = await s3_client.create_presigned_url(
        client_method="put_object",
        method_parameters={
            "Bucket": settings.S3_Bucket,
            "Key": f"application/registration/{find_application_id.get('application_id')}/{req_upload_document.document_type}/{first_char}{time_reformat}.jpg",
            "ContentLengthRange": [200, 1024],
        },
    )

我发现错误,因为参数对于内容长度范围无效。

botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "ContentLengthRange", must be one of: ACL, Body, Bucket, CacheControl, ContentDisposition, ContentEncoding, ContentLanguage, ContentLength, ContentMD5, ContentType, Expires, GrantFullControl, GrantRead, GrantReadACP, GrantWriteACP, Key, Metadata, ServerSideEncryption, StorageClass, WebsiteRedirectLocation, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, SSEKMSKeyId, SSEKMSEncryptionContext, BucketKeyEnabled, RequestPayer, Tagging, ObjectLockMode, ObjectLockRetainUntilDate, ObjectLockLegalHoldStatus, ExpectedBucketOwner

我可以在哪里把内容长度范围放在这个函数中?提前致谢

标签: pythonamazon-web-servicesamazon-s3

解决方案


推荐阅读