Boto - Uploading file to a specific location on Amazon S3

后端 未结 2 1096
暖寄归人
暖寄归人 2020-12-14 00:41

This is the code I\'m working from

import sys
import boto
import boto.s3

# AWS ACCESS DETAILS
AWS_ACCESS_KEY_ID = \'\'
AWS_SECRET_ACCESS_KEY = \'\'

bucket_         


        
相关标签:
2条回答
  • 2020-12-14 01:24

    All you should have to do is prepend the virtual directory path to the key name prior to uploading. For example:

    key_name = 'my test file'
    path = 'images/holiday'
    full_key_name = os.path.join(path, key_name)
    k = bucket.new_key(full_key_name)
    k.set_contents_from_filename(...)
    

    You may have to change that a bit for your application but hopefully that gives you the basic idea.

    0 讨论(0)
  • 2020-12-14 01:41

    You can also use this:

    from boto.s3.key import Key
    
    bucket = conn.get_bucket('images')
    k = Key(bucket)
    k.key = 'holiday/my_test_file.txt'
    

    It works like this in my s3_percent_uploader

    python.exe s3_percent_uploader.py test_upload.txt testbucket test/upload.txt
    

    after upload file will be in testbucket/test/upload.txt

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