Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python3 boto3 put object to s3

# Boto 2.x
from boto.s3.key import Key
key = Key('hello.txt')
key.set_contents_from_file('/tmp/hello.txt')

# Boto 3
s3.Object('mybucket', 'hello.txt').put(Body=open('/tmp/hello.txt', 'rb'))
Comment

boto3 s3

import logging
import boto3
from botocore.exceptions import ClientError
import os


def upload_file(file_name, bucket, object_name=None):
    """Upload a file to an S3 bucket

    :param file_name: File to upload
    :param bucket: Bucket to upload to
    :param object_name: S3 object name. If not specified then file_name is used
    :return: True if file was uploaded, else False
    """

    # If S3 object_name was not specified, use file_name
    if object_name is None:
        object_name = os.path.basename(file_name)

    # Upload the file
    s3_client = boto3.client('s3')
    try:
        response = s3_client.upload_file(file_name, bucket, object_name)
    except ClientError as e:
        logging.error(e)
        return False
    return True
Comment

boto3 python s3

response = client.abort_multipart_upload(
    Bucket='string',
    Key='string',
    UploadId='string',
    RequestPayer='requester',
    ExpectedBucketOwner='string'
)
Comment

python boto3 put_object to s3

file = open(r"/tmp/" + filename)
response = s3.meta.client.Bucket('<bucket-name>').put_object(Key='folder/{}'.format(filename), Body=file)
Comment

PREVIOUS NEXT
Code Example
Python :: Convert Int to String Using format() method 
Python :: flask windows auto reload 
Python :: create array numpy 
Python :: python concatenate dictionaries 
Python :: ner spacy 
Python :: pandas convert string to float 
Python :: join function python 
Python :: python flatten a list of lists 
Python :: pandas multiply all dataframe 
Python :: parse invoice python 
Python :: do while python 
Python :: how to delete a column in pandas dataframe 
Python :: from html to jupyter notebook 
Python :: generate table python 
Python :: #index operator in python 
Python :: df mask 
Python :: parse_dates 
Python :: python comments 
Python :: connect with database python 
Python :: r vs python 
Python :: seaborn stripplot range 
Python :: python console 
Python :: normalize a group in countplot 
Python :: python numpy array subtract 
Python :: how to run python code in python 
Python :: joining lists python 
Python :: sanke in python 
Python :: strip plot (normal) 
Python :: matplotlib use marker along variable 
Python :: python skip line 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =