我正在尝试上传到 S3,而我在 Web 控制台中不断遇到的错误是
传递调用“弹弓/上传请求”的结果时出现异常:类型错误:>无法读取未定义的属性“响应”
这是我的服务器端代码:
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!");
}
});
}
帮助将不胜感激!