无法让流星弹弓工作



我正试图让弹弓发挥作用,但遇到了困难,我在这里附上了我的代码。

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

"传递调用'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!");
  }
  });
}
});

lib

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;
      }
    });

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

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

在引用xhr之前,我检查了它,然后记录它(如果存在的话)。

最新更新