mardi 4 août 2015

How to upload multi files to amazon S3 directly with the form data?

I use codeigniter to build the site. There is a form in my site that upload multi videos (min 2 files, max 4 files ) , with a input box that allow user to input their email address.

In past days I use the codeingniter upload library to handle the upload, e.g. $_FILES and upload to the server.

Recently I switch to S3, and I would like to upload directly to S3 without temp store at my server.

Here is some code found on google:

   <form action="//<?php echo S3_BUCKET . "." . $service . "-" . S3_REGION; ?>.amazonaws.com"
          method="POST"
          enctype="multipart/form-data"
          class="direct-upload">

        <!-- Note: Order of these is Important -->
        <!-- Key and Content-Type can be filled in with JS -->
        <input type="hidden" name="key" value="${filename}">
        <input type="hidden" name="Content-Type" value="">
        <input type="hidden" name="acl" value="<?php echo S3_ACL; ?>">
        <input type="hidden" name="success_action_status" value="<?php echo $successStatus; ?>">
        <input type="hidden" name="policy" value="<?php echo $base64Policy; ?>">

        <input type="hidden" name="X-amz-algorithm" value="<?php echo $algorithm; ?>">
        <input type="hidden" name="X-amz-credential" value="<?php echo $credentials; ?>">
        <input type="hidden" name="X-amz-date" value="<?php echo $date; ?>">
        <input type="hidden" name="X-amz-expires" value="<?php echo $expires; ?>">
        <input type="hidden" name="X-amz-signature" value="<?php echo $signature; ?>">

        <input type="file" name="file">

        <input type="submit" value="submit">
    </form>

The problem is , if I would like to upload file pass through my server, that means I can not post any data to my server? How to upload the file directly to S3 as well as post the input box data to my server ?

Thanks a lot.




Aucun commentaire:

Enregistrer un commentaire