Audibase Recording App Banner

Lost?

Have an account? Register |

Samuel East

 

First in last out?

 


Working Amazon S3 Direct Upload Working Example

Hi everyone

I have been working closely with amazon s3 over the last couple off days and i am starting to find how useful it is to keep everything files folders onlinne.
I looking for a upload solution for amazon for a while. I found a great solution Amazon S3 Class this has great documentation.

If you download their class you can find a Amazon s3 upload solution.

Here is an example.

<?php

    S3::setAuth(awsAccessKey, awsSecretKey);

    $bucket = "upload-bucket";
    $path = "myfiles/"; // Can be empty ""

    $lifetime = 3600; // Period for which the parameters are valid
    $maxFileSize = (1024 * 1024 * 50); // 50 MB

    $metaHeaders = array("uid" => 123);
    $requestHeaders = array(
        "Content-Type" => "application/octet-stream",
        "Content-Disposition" => 'attachment; filename=${filename}'
    );

    $params = S3::getHttpUploadPostParams(
        $bucket,
        $path,
        S3::ACL_PUBLIC_READ,
        $lifetime,
        $maxFileSize,
        201, // Or a URL to redirect to on success
        $metaHeaders,
        $requestHeaders,
        false // False since we're not using flash
    );

    $uploadURL = "https://{$bucket}.s3.amazonaws.com/";

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>S3 Form Upload</title>
</head>
<body>
    <form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
    foreach ($params as $p => $v)
        echo "        <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
        <input type="file" name="file" /> <input type="submit" value="Upload" />
    </form>
</body>
</html>

This works great but i always have an issue with leaving a user with no reference off upload progress i have the assumption that with large downloads people will natural asume that the process has stopped or broke, and close or refresh the browser.

So from this solution i set about looking for a direct upload with a progress bar. This wasnt easy i spent a long time goggling etc, eventually i found uploadify which i thought would be a great soultion but this failed for me and i am still work on this so wait for the post.

Things i found when working with amazon when uploading a file it requires upload paramaters to be sent to amazon to allow for a secure upload. As you can see from the example above.

Please view the documentation here

http://docs.amazonwebservices.com/AmazonS3/latest/dev/

http://doc.s3.amazonaws.com/proposals/post.html

Ok so enough text this is what you are looking for the code.

Download the code and then change the information shown below.

// CHANGE EVERYTHING BELOW

define(AWS_ACCESS_KEY_ID,'YOUR AMAZON KEY');
define(AWS_SECRET_ACCESS_KEY,'YOU SECRET AMAZON KEY');
$S3_BUCKET = 'ENTER YOUR BUCKET';
$SUCCESS_REDIRECT = "CAN PUT A SUCCESS URL HERE IF YOU WANT";
$SWFRoot = "PUT IN THE ROOT URL TO YOUR WEBSITE";
AMAZON S3 DIRECT UPLOAD

Please make sure you upload this to the amazon bucket where you wish the files to upload into.

Call it crossdomain.xml and add the following.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" secure="false" />
</cross-domain-policy>

View the demo here

Let me know how you get on.

Leave a Reply


 

Wordpress Plugin Development

Currently we have been working on Wordpress plug-in development having the ability to create custom plug-in for our clients is great as we can now tailor them specifically. View More »

Titanium Mobile
App Development

Here at iSimpleDesign we take SEO and Website management very seriously as we are always striving to be at the top off our game, keeping ahead off the competition.

Content Management Systems

We offer an wide range off CMS systems Wordpress and Joomla to name a few, with a CMS you will be able to manage all you content and users etc... View More »

 

www.isimpledesign.co.uk, all rights reserved.

  • Clients

  • CRM

  • Design

  • Development

  • General

  • SEO