Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the exact code I used to get this to work...</p> <pre><code>var params = {}; $('#uploader').pluploadQueue({ runtimes: 'html5,flash', flash_swf_url: '/js/plupload/1.5.4/plupload.flash.swf', // Have to load locally url: 'https://s3.amazonaws.com/my-bucket-name', multiple_queues: true, preinit: { UploadFile: function (up, file) { up.settings.multipart_params = { key: file.name, filename: file.name, AWSAccessKeyId: 'my-aws-access-key', acl: 'private', policy: params[file.name]["policy"], signature: params[file.name]["signature"], success_action_status: '201' } } }, init: { FilesAdded: function (up, files) { plupload.each(files, function (file) { $.ajax({ url: '/r/prepare_raw_upload', type: 'post', data: { acl: 'private', bucket: 'my-bucket-name', file: file.name }, success: function (data) { if (data.success) { params[data.file] = { policy: data.policy, signature: data.signature }; } else if (data.message) { alert(data.message); } } }); }); } } }); </code></pre> <p>You'll notice in the FilesAdded event listener I have an ajax call. This retrieves the policy and the signature from my server for each file added.</p> <p>Here's the code on the back that sends back the policy and signature</p> <pre><code>public static Dictionary&lt;string, object&gt; prepareUpload(DateTime now, string acl, string bucket, string key, string file) { Dictionary&lt;string, object&gt; result = new Dictionary&lt;string, object&gt;(); ASCIIEncoding encoding = new ASCIIEncoding(); string policy = createUploadPolicy(now, acl, bucket, key); result.Add("policy", Convert.ToBase64String(encoding.GetBytes(policy))); result.Add("signature", createUploadSignature(policy)); result.Add("file", file); return result; } public static string createUploadPolicy(DateTime now, string acl, string bucket, string key) { ASCIIEncoding encoding = new ASCIIEncoding(); JavaScriptSerializer jss = new JavaScriptSerializer(); Hashtable policy = new Hashtable(); policy.Add("expiration", now.AddDays(1).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff'Z'")); ArrayList conditions = new ArrayList(); conditions.Add(new Hashtable { { "acl", acl } }); conditions.Add(new Hashtable { { "bucket", bucket } }); conditions.Add(new Hashtable { { "key", key } }); conditions.Add(new ArrayList { "starts-with", "$name", "" }); conditions.Add(new ArrayList { "starts-with", "$filename", "" }); conditions.Add(new ArrayList { "starts-with", "$success_action_status", "" }); policy.Add("conditions", conditions); return jss.Serialize(policy); } public static string createUploadSignature(string policy) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] policyBytes = encoding.GetBytes(policy); string policyBase64 = Convert.ToBase64String(policyBytes); byte[] secretKeyBytes = encoding.GetBytes(ConfigurationManager.AppSettings["AWSSecretKey"]); HMACSHA1 hmacsha1 = new HMACSHA1(secretKeyBytes); byte[] policyBase64Bytes = encoding.GetBytes(policyBase64); byte[] signatureBytes = hmacsha1.ComputeHash(policyBase64Bytes); return Convert.ToBase64String(signatureBytes); } </code></pre> <p>Very helpful links in making this work were...</p> <p><a href="https://stackoverflow.com/questions/4639471/how-do-i-make-plupload-upload-directly-to-amazon-s3">How do I make Plupload upload directly to Amazon S3?</a></p> <p><a href="http://codeonaboat.wordpress.com/2011/04/22/uploading-a-file-to-amazon-s3-using-an-asp-net-mvc-application-directly-from-the-users-browser/" rel="nofollow noreferrer">http://codeonaboat.wordpress.com/2011/04/22/uploading-a-file-to-amazon-s3-using-an-asp-net-mvc-application-directly-from-the-users-browser/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload