node.js - Creating public URL for Skipper upload on AWS -


i'm uploading image amazon web service s3 using skipper.js, creating public url file uploaded hasn't been possible using skipper.js. don't want use skipper-disk want upload s3 , able create publicly accessible url download file. code below , that's i've done

 imageupload: function(req, res) {     //console.log(req);     req.file('avatar').upload({         adapter: skipper,         key: 'key',         secret: 'secret',         bucket: 'bucketname'     }, function(err, fileuploaded){         if (err) {             console.log(err);             return res.negotiate(err);         }          if (fileuploaded.length === 0) {             return res.badrequest('no files uploaded');         }          var imageurl = fileuploaded[0].extra.location;         var imageky = fileuploaded[0].extra.key;         imageupload.create({urllink: imageurl, imagekey: imageky}).then(function(urladded){             if (urladded) {                 //return res.negotiate(err);                 //the linkadded link s3 provides image e.g https://bucket.s3.amazonaws.com/filename                 return res.json({linkadded: urladded});             }         })         .catch(function (err){             return res.badrequest(err);         });     }); } 

looks did upload code right assuming @ top of file have:

var skipper = require('skipper-s3') 

the actual fix has s3 config. in aws s3 console, bucket selected need select properties -> permissions -> edit bucket policy.

add code make bucket have public requests replace "bucketname" in resource param bucket name:

{     "version": "2012-10-17",     "statement": [         {             "sid": "addperm",             "effect": "allow",             "principal": "*",             "action": "s3:getobject",             "resource": "arn:aws:s3:::bucketname/*"         }     ] } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -