【问题标题】:can't get Meteor slingshot to work无法让 Meteor 弹弓工作
【发布时间】:2015-07-06 04:38:55
【问题描述】:

我正在尝试让 slingshot 工作,但遇到了困难,我在此附上我拥有的代码。

我在控制台得到的错误是:

“传递调用'slingshot/uploadRequest'的结果时出现异常:TypeError:无法读取未定义的属性'response'”

客户

Template.hello.events({
    'change .uploadFile': function(event, template) {

      event.preventDefault();

var uploader = new Slingshot.Upload("myFileUploads");

uploader.send(document.getElementById('uploadFile').files[0], function (error, downloadUrl) {
  if (error) {
    // Log service detailed response
    console.error('Error uploading', uploader.xhr.response);
    alert (error);
  }
  else{
    console.log("Worked!");
  }

  });
}
});

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

服务器

Slingshot.fileRestrictions("myFileUploads", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: null,
});


    Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, {
      AWSAccessKeyId: "my-AWSAccessKeyId",
      AWSSecretAccessKey: "my-AWSSecretAccessKey",
      bucket: "slingshot-trial-2",
      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;
      }

    });

【问题讨论】:

  • 你设法让它工作了吗?

标签: javascript meteor meteor-slingshot


【解决方案1】:

我看到了同样的问题,这是由于 xhr 为空 - 尝试删除引用它的控制台错误行,我假设您将开始看到带有实际错误消息的警报:

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

我最终检查了xhr,然后再引用它,然后记录它(如果存在)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多