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

后端 未结 3 1443
深忆病人
深忆病人 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:21

    Same problem here - I think this is because of Meteor not allowing CORS in the application header. I'm also trying to solve this very urgently.

    0 讨论(0)
  • 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();
        }
    }
    
    0 讨论(0)
  • 2021-02-11 05:28

    The problem can be that you requesting a SignedUrl for a PUT request but you later on POST the file to S3. You should PUT the file to S3 not POST.

    SignedUrls only allow GET and PUT right now.

    For more info see this answer: upload-file-from-angularjs-directly-to-amazon-s3-using-signed-url

    0 讨论(0)
提交回复
热议问题