Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I managed to get my code to work, the difficulty is to get <strong>the right policy</strong>. I'm using <a href="https://github.com/PRX/s3-swf-upload-plugin/tree/master/flex_src/src/com/elctech" rel="nofollow">elctech's library</a> to generate the s3 upload call.</p> <pre><code>import com.elctech.*; public class Uploader{ private var _options : S3UploadOptions = new S3UploadOptions(); // ... public function uploadPDF(tempFile:File):void{ _options.FileSize = tempFile.size.toString(); _options.FileName = getFileName(tempFile); _options.ContentType = 'application/pdf'; _options.key = certificate['key'] + _options.FileName; _options.policy = certificate['policy']; _options.signature = certificate['signature']; _options.bucket = certificate['bucket']; _options.AWSAccessKeyId = certificate['accessKey']; _options.acl = certificate['acl']; _options.Expires = certificate['expiration']; _options.Secure = 'false'; _options.successactionstatus = certificate['sas']; var request:S3UploadRequest = new S3UploadRequest(_options); configureUploadListeners(request); try { request.upload(tempFile); } catch(e:Error) { trace("An error occurred: " + e); } } private function getFileName(file:FileReference):String { var fileName:String = file.name.replace(/^.*(\\|\/)/gi, '').replace(/[^A-Za-z0-9\.\-]/gi, '_'); return fileName; } } </code></pre> <p>I get the amazon s3 certificate from our main Rails application via our API, here's what the policy generation looks like:</p> <pre><code>def certificate bucket = ENV['S3_BUCKET'] access_key = ENV['S3_KEY'] secret = ENV['S3_SECRET'] key = "temp/" expiration = 10.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z') max_filesize = 500.megabytes acl = 'public-read' sas = '201' policy = Base64.encode64( "{'expiration': '#{expiration}', 'conditions': [ {'bucket': '#{bucket}'}, ['starts-with', '$key', '#{key}'], {'acl': '#{acl}'}, {'Content-Type': 'application/pdf'}, {'Content-Disposition': 'attachment'}, ['starts-with', '$Filename', ''], ['eq', '$success_action_status', '201'] ]} ").gsub(/\n|\r/, '') signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret, policy)).gsub(/\n| |\r/, '') { :access_key =&gt; access_key, :key =&gt; key, :policy =&gt; policy, :signature =&gt; signature, :sas =&gt; sas, :bucket =&gt; bucket, :acl =&gt; acl, :expiration =&gt; expiration } end </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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