我有一个工作流星/科尔多瓦应用程序,它使用弹弓上传到 AWS/S3。我可以从浏览器和 iOS 上传和查看应用内照片。
但是,在 Android 上,我无法从 slingshot 提供的 AWS 链接加载照片并存储在我的数据库中,当我尝试上传照片时,我收到一条错误消息:
"error : failed to upload file to cloud storage [-0]"
有没有什么我错过的/我应该为 android 配置 slingshot/我的应用程序的特定于 android 的东西?任何帮助将不胜感激。谢谢!
相关的客户端代码(减去文件限制):
//upload to AWS once file is selected
'change #imgUpload' : function(){
var uploader = new Slingshot.Upload("uploadFiles");
var questionId = Session.get('selectedQuestion');
uploader.send(document.getElementById('uploadInput').files[0], function (error, downloadUrl) {
if (error) {
// Log service detailed response
console.log(error)
console.error('Error uploading' );
alert (error);
}
else {
Meteor.call('uploadImage', questionId, downloadUrl);
}
});
相关的服务器端方法:
'uploadImage' : function(questionId, downloadUrl){
check(questionId, String);
check(downloadUrl, String);
questionsList.update({_id: questionId},
{$set: {
picUrl: downloadUrl
}
});
}, //end upload image
相关的服务器端指令(减去文件限制):
Slingshot.createDirective("uploadFiles", Slingshot.S3Storage, {
bucket: <bucketname>,
acl: "public-read",
authorize: function(){
//you can't upload if youre not logged in
if(!this.userId){
var message = "Please log in before posting files";
throw new Meteor.Error("Login Required", message);
}
return true;
},
key: function(file){
//store file in a directory based on a users team name
var teamName = Meteor.user().roles.defaultGroup[0]
return teamName + "/" + file.name;
}
});
相关的 mobile_config.js 访问规则:
App.accessRule('https://<app-name>.herokuapp.com/*');
App.accessRule('http://<app-name>.herokuapp.com/*');
App.accessRule('https://s3.amazonaws.com/<bucketname>/*');
App.accessRule('http://localhost:3010/*');
显示图片的相关模板:
{{#if theQuestion.picUrl}}
<img src="{{theQuestion.picUrl}}" width="300px" height="300px" class="userPic">
{{/if}}
上传图片的相关模板:
<template name="uploader">
<form id="imgUpload">
<input id='uploadInput' class="fileLoader" name="file" type="file">
<label for="file" class="uploadWords">Tap here to upload/take a picture</label>
</form>
文件限制:
Slingshot.fileRestrictions("uploadFiles", {
allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited)
});