スリングショットを使用して AWS/S3 にアップロードする作業中の meteor/cordova アプリがあります。ブラウザと iOS からアプリ内で写真をアップロードして表示できます。
ただし、Android では、slingshot によって提供され、データベースに保存されている AWS リンクから写真を読み込むことができません。写真をアップロードしようとすると、次のようなエラーが表示されます。
"error : failed to upload file to cloud storage [-0]"
Android 向けに一般的にパチンコ/私のアプリを構成するために見逃した/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/*');
pic を表示する関連テンプレート:
{{#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)
});