Direct Browser Upload to S3 with Meteor, jQuery and the AWS SDK

后端 未结 3 1445
深忆病人
深忆病人 2021-02-11 04:37

I have got into almost every resource on the topic, but still need your help to make this work. I want to directly upload files to my S3 directly from the browser in my Meteor a

3条回答
  •  不知归路
    2021-02-11 05:22

    To get this working I had to add a couple of parameters to the s3.getSignedUrl call:

    ContentType: mimeType,
    Body: '',
    "ACL": 'public-read'
    

    Full method:

    Meteor.methods({
        requestUpload: function(filename, mimeType) {
            var fut = new Future();
            new Fiber(function() {
                var params = {
                    Bucket: MY_BUCKET,
                    Key: new Date().getTime() + "_" + filename,
                    ContentType: mimeType,
                    Body: '',
                    "ACL": 'public-read'
                };
                var surl = s3.getSignedUrl('putObject', params, function(err, surl) {
                    if (!err) {
                        console.log("signed url: " + surl);
                        fut.return(surl);
                    } else {
                        console.log("Error signing url " + err);
                        fut.return();
                    }
                });
            }).run();
            return fut.wait();
        }
    }
    

提交回复
热议问题