如何通过boto3的upload_file传递资助?

时间:2016-08-30 15:08:58

标签: python python-2.7 boto3

我有一个使用AWS CLI的命令

aws s3 cp y:/mydatafolder s3://<bucket>/folder/subfolder --recursive --grants read=uri=http://policyurl 

第一部分在python中很容易,我可以使用os.walk遍历文件夹并获取文件并使用boto3.s3client.upload_file命令上传文件。我正在努力的第二部分是--grants read部分。

我需要调用什么boto3函数才能执行此操作?

由于

1 个答案:

答案 0 :(得分:0)

upload_file来电中,您需要在GrantRead中传递ExtraArgs。一般来说,您可以传递put_object将采用这种方式的任何参数。例如:

import boto3

s3 = boto3.client('s3')
file_path = '/foo/bar/baz.txt'
s3.upload_file(
    Filename=file_path,
    Bucket='<bucket>',
    Key='key',
    ExtraArgs={
        'GrantRead': 'uri="http://policyurl"'
    }
)