0

我正在尝试让弹弓工作,但遇到了困难,我在这里附上了我拥有的代码。

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

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

客户

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

    });
4

1 回答 1

0

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

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

我最终xhr在引用它之前进行了检查,然后如果它存在则记录它。

于 2015-07-05T20:38:55.450 回答