Upload a file using boto

import boto conn = boto.connect_s3('', '') mybucket = conn.get_bucket('data_report_321') 

I can load the file from the bucket using the following code.

 for b in mybucket: print b.name b.get_contents_to_filename('0000_part_00', headers=None, cb=None, num_cb=10, torrent=False, version_id=None, res_download_handler=None, response_headers=None) 

But I can not upload the file . I get an error: AttributeError: object 'str' does not have attribute 'tell'

send_file and set_contents functions properly.

 for b in mybucket: b.send_file('mytest.txt', headers=None, cb=None, num_cb=10, query_args=None, chunked_transfer=False, size=None) b.set_contents_from_file('mytest.txt', headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None, reduced_redundancy=False, query_args=None, encrypt_key=False, size=None, rewind=False) 

How to upload a file from the current directory of the local server to the S3 bucket using boto?


Update: I need to first declare the key (file name) of the downloaded file before calling the set_contents_from_filename function.

 k = boto.s3.key.Key(mybucket) k.key = 'uploaded_file.txt' k.set_contents_from_filename("myteswt.txt") 
+6
source share
2 answers

Both send_file and set_contents_from_file take a File object for the first argument. If you want to pass a string, you should see set_contents_from_filename .

+9
source

You can use this utility script: https://github.com/TimelyToga/upload_s3

 python upload_s3.py <filename> [key_to_upload_as] 

This will load any file into the s3 bucket that you specify.

Although when loading set_contents_from_file the python File object is executed.

-2
source

Source: https://habr.com/ru/post/954382/


All Articles