Showing posts with label Amazon. Show all posts
Showing posts with label Amazon. Show all posts

Friday 10 October 2014

Download Videos from Amazon S3 - PHP

Download Videos from Amazon S3 - PHP

            $newFileName = "download_filename.mp4";
            header('Content-Type: video/mp4');
            header('Content-Disposition: attachment; filename="' . $newFileName . '"');
            $my_aws_key = 'AWS_KEY';
            $my_aws_secret_key = 'AWS_SCRET_KEY';
            $s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);
            $newFileName = "S3_download_filename.mp4";
            $response = $s3->getObjectStream("$newFileName");//download stream from s3

Wednesday 14 May 2014

PHP Upload File In Amazon S3 Bucket - Code Snippets

PHP Upload File In Amazon S3 Bucket - Code Snippets

Get List of buckets in Amazon S3 bucket and upload a file in Amazon S3 bucket with Zend Framework.

Uploading files in zend framework is very simple because zend framework provides the API which is very simple to use.

Please use following code to upload photos in zend framework.
$my_aws_key = 'AWS_KEY';
$my_aws_secret_key = 'AWS_SECRET_KEY';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);

/** Get List of buckets * */
$list = $s3->getBuckets();
foreach ($list as $bucket) {
    echo "Bucket: $bucket\n";
/** Get List of buckets * */

/** get Bucket Files **/
$files = $s3->getObjectsByBucket("BUCKET_NAME");
foreach ($files as $file) {
    echo "File: $file\n";
/** get Bucket Files **/

$imageName = '';
try {
    $s3->putFile($imageName, "BUCKET_NAME/ZFCE-logo-XS.jpg", array(
        Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
        'x-amz-storage-class' => 'REDUCED_REDUNDANCY'
die('uploaded successfully');
} catch (Exception $e) {

Monday 16 September 2013

Amazon S3 Introduction - Basics

Amazon S3 Introduction - Basics

Important Terms

S3: Simple Storage Services
AWS: Amazon Web Services
SDK: Software Development Kit
IAM: Identity Access Management

What is AmazonS3

It is Simple Stored Service provided by Amazon where you can manage files and can put authorized on these files.
Amazon will charge only when you upload/download the files. These files can be easily managed through SOAP, HTTP OR with use of third party Services.

Benefits of S3

  1. Available through API REST/SOAP.
  2. Durability
  3. Economic
  4. Fast
  5. Scalable
  6. Web store not FileSystem

Amazon S3 Concepts 

Bucket: A Bucket is Amazon terminology for what amounts to a folder or directory of files. Bucket names have to be unique across the service. Its in the root and you can create many bucket as you want. You can places data or directory inside the bucket. You can create 100-150 bucket per account. For each bucket, you can control access to the bucket (who can create, delete, and list objects in the bucket), view access logs for the bucket and its objects, and choose the geographical region where Amazon S3 will store the bucket and its contents.

Bucket Naming Convention

  1. Can’t have slahes
  2. It can have lowercase character, number, period(.) and hypen(-)
  3. Should be between 3-255 characters
  4. Must be start with number or letter
  5. Should not have underscore(_)
  6. Must not be inform of IP (
  7. Must not end with –
  8. Should not be .- or -. together

Object: When you upload file or folder in the bucket that is known as object. You can also set the permission on that ozbject. To upload folder you must enable “Enable Enhanced Uploader” of java applet. Objects consist of object data and metadata. The data portion is opaque to Amazon S3

Key: It is unique identifier for an object within the bucket. Every object in a bucket has exactly one key. Because the combination of bucket, key and version Id form uniquely object.
 For example, in the URL, 
here "doc" is the name of the bucket and "2006-03-01/AmazonS3.wsdl" is the key

Region: You can choose the geographical Region where Amazon S3 will store the buckets you create. You might choose a Region to optimize latency, minimize costs, or address regulatory requirements.

Features of S3

Reduced Redundancy Storage (RSS): RRS enables customers to reduce their costs by storing non-critical, reproducible data at lower levels of redundancy than Amazon S3's standard storage.

Bucket Policies: Create bucket with permission. An account can grant one application limited read and write access, but allow another to create and delete buckets as well. An account could allow several field offices to store their daily reports in a single bucket, allowing each office to write only to a certain set of names (e.g. "Nevada/*" or "Utah/*") and only from the office's IP address range. 

AWS Identity and Access Management :
Create users and groups under your organization's AWS account
Easily share your AWS account resources between the users in the account
Assign unique security credentials to each user
Granularly control users access to services and resources
Get a single AWS bill for all users under the AWS account

Access Control Lists


Create Bucket
Write object in bucket
Read bucket
Delete Object
Listing keys

Amazon S3 API

REST Interface: In REST, you use standard HTTP requests to create, fetch, and delete buckets and objects.

SOAP Interface: The most common way to use SOAP is to download the WSDL (go to, use a SOAP toolkit such as Apache Axis or Microsoft .NET to create bindings, and then write code that uses the bindings to call Amazon S3

Paying For Amazon S3
You need not to pay in starting and need to choose any plan. Just use as you need and they will charge @ the end of the month.