working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,777 snippets matching: amazon

    public by fabio.nosenzo @ Amazon_AWS_Python_API  588176  5  8  -1

    Amazon S3 Aws - S3Connection object from python boto API

    This snippet is about the S3Connection object provided by python boto package for Amazon AWS API. Here the __init__ method is listed with all its variables. The AWSAuthConnection object is initialized and it handles all the data for managing requests and response from Amazon AWS service. Path: [boto/s3/connection.py] Learn more about S3Con
    import boto.utils
    from boto.connection import AWSAuthConnection
    
    class S3Connection(AWSAuthConnection):
        DefaultHost = boto.config.get('s3', 'host', 's3.amazonaws.com')
        DefaultCallingFormat = boto.config.get('s3', 'calling_format', 'boto.s3.connection.SubdomainCallingFormat')
        QueryString = 'Signature=%s&Expires=%d&AWSAccessKeyId=%s'
    
        def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
                     is_secure=True, port=None, proxy=None, proxy_port=None,
                     proxy_user=None, proxy_pass=None,
                     host=DefaultHost, debug=0, https_connection_factory=None,
                     calling_format=DefaultCallingFormat, path='/',
                     provider='aws', bucket_class=Bucket, security_token=None,
                     suppress_consec_slashes=True, anon=False,
                     validate_certs=None):
            if isinstance(calling_format, str):
                calling_format=boto.utils.find_class(calling_format)()
            self.calling_format = calling_format
            self.bucket_class = bucket_class
            self.anon = anon
            AWSAuthConnection.__init__(self, host,
                    aws_access_key_id, aws_secret_access_key,
                    is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
                    debug=debug, https_connection_factory=https_connection_factory,
                    path=path, provider=provider, security_token=security_token,
                    suppress_consec_slashes=suppress_consec_slashes,
                    validate_certs=validate_certs)

    public by lbottaro @ Amazon_AWS_Python_API  304442  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket](http://www.snip2code.com/Snippet/4892/Amazon-Aws-S3---Creating-a-bucket-in-pyt) [How to upload a file to a bucket](http://www.sn
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    
    key = bucket.get_key('foobar.pdf')
    key.get_contents_to_filename('/home/luca/documents/foobar.pdf')

    public by mporru @ Amazon_AWS_PHP_API  320881  0  5  0

    Amazon AWS - PHP: Generate signed expiring download URL

    This snippet demonstrates how to generate a download URL for a file stored in your S3 Bucket. This will work for all files, even ACL private files. Download URL will be active for the specified time. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'test1.txt';
    $bucketName = 'myBucketName';
    
    $url = $s3->get_object_url($bucketName, $fileName, '1 hour');
    
    echo("Download url: <a href=\"$url\">$url</a>\n");
    ?>

    public by mporru @ Amazon_AWS_PHP_API  210390  0  5  0

    Amazon AWS - PHP: Upload a File taking it from your server

    This snippet demonstrates how to upload a file to a S3 Bucket, taking it form a your server. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    $s3 = new AmazonS3();
    // Create Object is pretty self explanatory:
    // Arg 1: The bucket where your file will be created.
    // Arg 2: The name of your file.
    // Arg 3: An array of Options.
    //        In this case we're specifying the &quot;fileUpload&quot; option (a file on your server)
    //        and the ACL setting to allow this file to be read by anyone.
    $response=$s3->create_object('myBucketName', 'LighthouseNew.jpg', 
    array('fileUpload'=>'./Lighthouse.jpg', 'acl'=>AmazonS3::ACL_PUBLIC));
    // Check if everything is okay.
    if ($response->isOK()) {
    	echo("File uploaded correctly");
    } else {
    	echo("There was an error uploading the file!");
    }
    ?>

    public by mporru @ Amazon_AWS_PHP_API  133713  0  5  0

    Amazon AWS - PHP: Create a new Bucket

    This snippet demonstrates how to create a new Amazon S3 Bucket. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account. Taken from: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
    <?php
    require_once 'sdk.class.php';
    
    // Create the s3 Object from the SDK
    $s3 = new AmazonS3();
    // Run the Method: Create Bucket.
    // Arg 1: 'my-unique-bucket-name' is the name of your new bucket.
    // Arg 2: The geographical region where your data will be stored.
    // Arg 3: Tells Amazon to make your files readable by anyone like regular files hosted on a web server.
    $response = $s3->create_bucket('my-unique-bucket-name', AmazonS3::REGION_US_E1, AmazonS3::ACL_PUBLIC);
    // The response comes back as a Simple XML Object
    // In this case we just want to know if everything was okay.
    // If not, report the message from the XML response.
    if ((int) $response->isOK()) {
        echo 'Created Bucket';
    } else {
        echo (string) $response->body->Message;
    }
    
    ?>

    public by lbottaro @ Amazon_AWS_Python_API  5471  5  8  1

    Amazon S3 Aws - Generate unsigned object download URLs

    This python code generates unsigned URL to download a public file from Amazon S3 storage. Note that unsigned URL can be generated for object with public acl.
    # Create an unsigned download URL for hello.txt. 
    # Requirements:
    # file hello.txt is public by setting its ACL 
    
    # Get hello.txt file key from bucket
    hello_key = bucket.get_key('hello.txt')
    # Create the unsigned URL
    hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
    print hello_url
    

    public by lbottaro @ Amazon_AWS_Python_API  10733  32  8  0

    Amazon S3 Aws - Change an object's acl using boto API

    This code shows how to change the access rights on a file uploaded on S3 storage. This example sets the object foo_bar.txt to be publicly readable, and secret.txt to be private. Supported acl values defined in boto.gs.acl.py. CannedACLStrings = ['private', 'public-read', 'project-private', 'public-read-write', 'authenticated-read', 'buc
    # Public ACL example
    # Here you get the key reference for file foo_bar.txt
    foo_bar_key = bucket.get_key('foo_bar.txt')
    # This set the foo_bar file publicly readable
    foo_bar_key.set_canned_acl('public-read')
    
    # Private ACL example
    # Here you get the key reference for file secret.txt
    secret_key = bucket.get_key('secret.txt')
    # This set the secret.txt file as private
    secret_key.set_canned_acl('private')

    public by lbottaro @ Amazon_AWS_Python_API  6434  19  8  1

    Amazon S3 Aws - How to delete a bucket using boto API

    This example shows how to remove a bucket invoking python API provided by boto. Important note: the bucket must be empty.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # Remove the bucket
            conn.delete_bucket(bucket.name)

    public by lbottaro @ Amazon_AWS_Python_API  6271  3  8  0

    Amazon S3 Aws - How to get content information for a given bucket using boto python api

    This snippet shows how to iterate through your own Amazon S3 buckets and list the available content.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # For each bucket get all data content put into the bucket
            for key in bucket.list():
                    # Get name, size and date
                    print "{name}\t{size}\t{modified}".format(
                            name = key.name,
                            size = key.size,
                            modified = key.last_modified,
                            )

    public by lbottaro @ Amazon_AWS_Python_API  6141  1  8  1

    Amazon S3 Aws - get_bucket method in boto python API

    This example shows how to get a single key from a bucket and then write that key to a file.
    from boto.s3.connection import S3Connection
    from boto.s3.key import Key
    
    # Get connection using Amazon secret and access keys
    conn = S3Connection('<aws secret key>', '<aws access key>')
    
    # Get the bucket with name 'bucketname'
    bucket = conn.get_bucket('bucketname')
    
    # Get the key reference to file 'picture.jpg'
    key = bucket.get_key("picture.jpg")
    
    # Open file in write mode
    fp = open ("picture.jpg", "w")
    
    # Set the reference to file
    key.get_file (fp)
    • Public Snippets
    • Channels Snippets