working on it ...

Filters

Explore Public Snippets

Sort by

Found 966 snippets matching: bucket

    public by lbottaro @ Amazon_AWS_Python_API  304493  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  320929  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  210402  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  133723  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  6445  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 mporru @ Amazon_AWS_PHP_API  12815  16  6  0

    Amazon AWS - PHP: List objects in Bucket

    This snippet demonstrates how to list Objects in a S3 Bucket. The procedure iterates, reading 1000 snippets then reading every page until the end. 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();
    
    $bucketName = 'myBucketName';
    $isTruncated=false;
    $lastObj = '';
    do {
    	if (!$isTruncated)
    		$response = $s3->list_objects($bucketName);	// first 1000 items
    	else 
    		$response = $s3->list_objects($bucketName, array('marker' => $lastObj)); // next items
    		
    	if (!$response->isOK())
    		break;
    	
    	$objects = $response->body->Contents;
    	foreach ($objects as $obj) {
    		echo("<b>" . $obj->Key . "</b> " . $obj->Size . " " . $obj->LastModified . "<br />");
    	}
    	$isTruncated = $response->body->IsTruncated == 'true';
    	$lastObj = $obj->Key;
    	echo("$isTruncated - $lastObj");
    } while($isTruncated)
    ?>

    public by lbottaro @ Amazon_AWS_Python_API  6287  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  4612  1  8  2

    Amazon S3 Aws - Creating a bucket in python

    This code shows how to create a new bucket using boto API on a S3 Amazon account. Please note that the name of the bucket must be unique, different from any other bucket existing in Amazon S3 storage. For this reason you can add some random value to make it unique.
    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)
    
    # This creates a new bucket called myBucket
    bucket = conn.create_bucket('myBucket')

    public by lbottaro @ Amazon_AWS_Python_API  4158  0  8  1

    Amazon S3 Aws - Adding a file to a bucket using boto API

    This python example shows how to add some content to an existing bucket to Amazon S3. You need to add a new key, named as the filename and then invoke the set\_contents\_from\_string method to add a new file. Prerequisites: You need an existing bucket.
    # This creates a file hello.txt with the string "Hello World!"
    key = bucket.new_key('hello.txt')
    key.set_contents_from_string('Hello World!')

    public by lbottaro @ Amazon_AWS_Python_API  4006  1  8  0

    Amazon S3 Aws - How to get the reference to a bucket

    This code shows how to get the reference to an existing bucket on Amazon S3 account, using boto python API. You need to specify the bucket name as unique key and invoke the get_bucket method provided by S3Connection object. Prerequisites: You need an existing bucket.
    bk = conn.get_bucket('my_bucket_name')
    • Public Snippets
    • Channels Snippets