Integrate Amazon S3 with Zend Framework

In this web development tutorial I will give you a few neccesary steps for uploading large files to an Amazon account using Zend Framework 1.

Note: If you want to use Amazon S3 for storing large filses, first you have to create an Amazon S3 account here. Please take note that the Amazon S3 is not a free service.

zend_amazon_main

Step 1

Create an Amazon Access Keys

After following all the steps here, you will get the access keys, that have two parts and look like that:

  • Access key ID example: AKIAIOSFODNN7EXAMPLE
  • Secret access key  example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

 

Step 2

Create an Amazon Bucket

Follow the steps here to creat a Bucket and you will get something like that:

amazons3

 

Step 3

Connect to Amazon S3 using Zend_Service_Amazon_S3 class

We will store our Access key ID, Secret access key and Bucket in some variables like bellow:

After doing that, we instantiate Zend_Service_Amazon_S3 with keys:

 

Step 4

Creating objects

For this purpose we can use one of the following methods:  putObject(), putFile() or putFileStream(). In our case we will use putFile().

When we create new objects we can set attributes for each file. An exemple is the availability for the users. In our case users can only read files.

 

Modifying an existing object

For modify an object we simply use the method call for creating the object and the object will be replaced.

 

Deleting an existant object

For remove an object fro Amazon S3 we call removeObject() method.

 

Get information about an object

  • isObjectAvailable() method:  check if the object exists

  • getInfo()
    • Retrieves information about a given object
    • outputs:
      • file type
      • file size
      • mtime
      • etag

 

Step 5

How can outside users access files you store in Amazon S3 buckets?

Above are listed the posibilities:

  • http://[bucketName].s3.amazonaws.com/[objectName]
  • http://s3.amazonaws.com/[bucketName]/[objectName]

 

Summary

This was a basic tutorial how to work with Amazon S3 service using Zend Framework v1. For any other question regarding this subject, don’t hesitate to post your question below.

Bogdan Rusu

Working in development for more then 10 years, Bogdan Rusu is the CTO of Design19 web agency. Highly skilled in PHP development and usage of CMS like Wordpress, Magento, Zend framework, but also custom built platforms based on PHP, Bogdan has driven the team to a higher level of proficiency in development.

Leave a comment

Your email address will not be published. Required fields are marked *

  • All fields marked with * are mandatory