Make a file in s3 public using python and boto

后端 未结 4 1894
半阙折子戏
半阙折子戏 2021-02-18 21:20

I have thins link below, and when I try to acess it it appears an xml file saying \"Acess denied\".

And I need to go to aws managment console and make this part-00

相关标签:
4条回答
  • 2021-02-18 21:30

    Boto3 setting ACL. Good question/answers here.

    bucket.Acl().put(ACL='public-read')
    obj.Acl().put(ACL='public-read')
    

    Use of obj.Acl().put... is very helpful when moving or manipulating items. Especially helpful if scripting/procedural.

    via https://boto3.readthedocs.io/en/latest/guide/migrations3.html#access-controls.

    0 讨论(0)
  • 2021-02-18 21:31
    from boto3.s3.transfer import S3Transfer
    import boto3
    
    # ...
    # have all the variables populated which are required below
    
    client = boto3.client('s3', aws_access_key_id=access_key,
                          aws_secret_access_key=secret_key)
    transfer = S3Transfer(client)
    transfer.upload_file(filepath, bucket_name, folder_name+"/"+filename)
    response = client.put_object_acl(ACL='public-read', Bucket=bucket_name, Key="%s/%s" % (folder_name, filename))
    
    0 讨论(0)
  • 2021-02-18 21:42

    This seems to work with boto 2.42.0 and Python 3

    s3 = boto.connect_s3()
    b = s3.get_bucket('brianray')
    k = Key(b)
    k.key = new_file_name
    k.set_contents_from_filename(new_file_name)
    k.set_acl('public-read')
    k.generate_url(expires_in=0, query_auth=False)
    
    0 讨论(0)
  • 2021-02-18 21:53

    This should give you an idea:

    import boto.s3
    conn = boto.s3.connect_to_region('us-east-1')  # or region of choice
    bucket = conn.get_bucket('myFolder')
    key = bucket.lookup('uploadedfiles/2015423/part-00000')
    key.set_acl('public-read')
    

    In this case, public-read is one of the canned ACL policies supported by S3 and would allow anyone to read the file.

    0 讨论(0)
提交回复
热议问题