如何使用meteor slingshot正确上传到Amazon S3?

时间:2015-04-12 04:41:48

标签: node.js amazon-web-services meteor amazon-s3 meteor-slingshot

我正在尝试上传到S3,而我在网络控制台中遇到的错误是

  

提供调用'slingshot / uploadRequest'的结果时出现异常:TypeError:>无法读取未定义的属性'response'

这是我的服务器端代码:

Slingshot.fileRestrictions("Test1", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited)
});


Slingshot.createDirective("Test1", Slingshot.S3Storage, {

  AWSAccessKeyId: "Key",
  AWSSecretAccessKey: "Key",
  bucket: "bucketname",


  acl: "public-read",

  authorize: function () {
    //Deny uploads if user is not logged in.

    },

  key: function (file) {
    //Store file into a directory by the user's username.
    return file.name;
  }

客户端代码:

Template.first.events({
    'change .fileInput': function(event, template) {

      event.preventDefault();

var uploader = new Slingshot.Upload("Test1");
var docc = document.getElementById('fileup').files[0];
console.log(docc);

uploader.send(docc, function (error){
  if (error) {


    console.error('Error uploading', uploader.xhr.response);

    alert (error);
  }
  else{
    console.log("Worked!");
  }

  });
  }

非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

以下行失败。 xhr为空

console.error('Error uploading', uploader.xhr.response);

记录如下错误并从那里调试

console.error('Error uploading', error);