Giter Club home page Giter Club logo

Comments (13)

selbyk avatar selbyk commented on August 17, 2024

Node/Express backend implementation, jic. I'm pretty sure this is working, though.

// Import required modules
var crypto = require('crypto'),
      shasum = crypto.createHash('sha1'),
      base64 = function(str){
          var buf = new Buffer(str).toString('base64');
          return buf;
      };

// Setup AWS Variables
var S3_BUCKET_NAME = 'bucket',
      S3_SECRET_KEY = process.env.AWS_SECRET_KEY,
      S3_ACCESS_KEY = process.env.AWS_ACCESS_KEY;

// Export Express.js routes
module.exports = function(app) {
  app.get('/api/admin/files/sign', function (req, res) {
    var params = {
        "name": req.query.name,
        "size": req.query.size,
        "type": req.query.type
    };

    // PUT request to S3 must start within 5 minutes
    var expires = new Date();
    expires.setMinutes(expires.getMinutes() + 5); // 5 minute later

    var objectName = params.name,
        amzHeaders = "x-amz-acl:public-read",
        mimeType = params.type;

    var bucketKey = "uploads/" + params.name; // directory/file path

    var policy= {
      expiration: expires,
      conditions: [
        { bucket: S3_BUCKET_NAME },
        { acl: 'public-read' },
        { expires: expires },
        { success_action_status: '201' },
        [ 'starts-with', '$key', '' ],
        [ 'starts-with', '$Content-Type', '' ],
        [ 'starts-with', '$Cache-Control', '' ],
        [ 'content-length-range', 0, 524288000 ]
      ]
    };

    var policy64 = base64(JSON.stringify(policy));

    var hash, hmac;

    hmac = crypto.createHmac('sha1', S3_SECRET_KEY);

    // change to 'binary' if you want a binary digest
    hmac.setEncoding('base64');

    // write in the text that you want the hmac digest for
    hmac.write(policy64);

    // you can't read from the stream until you call end()
    hmac.end(function(){
      // read out hmac digest
      hash = hmac.read();
      //console.log("The URL is", url);
      console.log('file ' + params.type + ' signed expires ' + expires);
      res.send({
          "acl": "public-read",
          "awsaccesskeyid": S3_ACCESS_KEY,
          "bucket": S3_BUCKET_NAME,
          "region": "us-west-2",
          "Cache-Control": "max-age=259200, public",
          //"AWSAccessKeyId": S3_ACCESS_KEY,
          "Content-Type": params.type,
          "expires": expires.toISOString(),
          "key": bucketKey,
          "policy": policy64,
          "signature": hash,
          "success_action_status": "201"
      });
    });
  });
...

from ember-uploader.

selbyk avatar selbyk commented on August 17, 2024

"ember-uploader": "0.3.4" in bower.json works, ember-uploader 0.3.5 breaks functionality. Is there a reason for this? If so, could you update the readme? Thanks!

from ember-uploader.

digitaltoad avatar digitaltoad commented on August 17, 2024

I will look into this. There was a change to the way the promise was resolved/rejected and I believe this is the culprit.

from ember-uploader.

rahult avatar rahult commented on August 17, 2024

Getting the same issue with 0.3.5

from ember-uploader.

selbyk avatar selbyk commented on August 17, 2024

If I had to guess, it looks like this change is the culprit: c5735be...3ffcef1#diff-7da8f6c08d157e1189a4f51cec1e5014R33

from ember-uploader.

selbyk avatar selbyk commented on August 17, 2024

c5735be...3ffcef1#diff-cd19b38f35e5030671d7f73532b875bdR36 *

from ember-uploader.

digitaltoad avatar digitaltoad commented on August 17, 2024

Can you try 2de1ba4

from ember-uploader.

rahult avatar rahult commented on August 17, 2024

Awesome 2de1ba4 worked 👍

from ember-uploader.

selbyk avatar selbyk commented on August 17, 2024

Oops, didn't notice your reply. Will test it out when I get back from class. ^^

from ember-uploader.

digitaltoad avatar digitaltoad commented on August 17, 2024

If it works for you, I'll go ahead and make a new build.

from ember-uploader.

selbyk avatar selbyk commented on August 17, 2024

Works like a charm! Sorry for the delayed response.

I didn't realize you could just bower install by commit. Pretty nifty. Thanks for looking into it. ^^

from ember-uploader.

digitaltoad avatar digitaltoad commented on August 17, 2024

Fixed in 2de1ba4

from ember-uploader.

digitaltoad avatar digitaltoad commented on August 17, 2024

New version has been released.

from ember-uploader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.