我试图让弹弓工作但是很难过,我附上了我的代码。
我在控制台得到的错误是:
“提供调用'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;
}
});
答案 0 :(得分:0)
我看到同样的问题,原因是xhr
为空 - 尝试删除引用它的控制台错误行,我假设您已开始看到带有实际错误的警报消息:
console.error('Error uploading', uploader.xhr.response);
我最后在引用它之前检查了xhr
,然后记录它(如果存在的话)。