I have a working meteor/cordova app that uses slingshot to upload to AWS/S3. I am able to upload and view photos in-app from the browser and from iOS.
However, on Android I am unable to load photos from the AWS link provided by slingshot and stored in my database, and when I try to upload a photo I get an error that reads:
"error : failed to upload file to cloud storage [-0]"
Is there anything android-specific that I have missed/that I should do to configure slingshot/my app in general for android? Any help would be very much appreciated. Thanks!
relevant client-side code (minus file restriction):
//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);
}
});
relevant server-side method:
'uploadImage' : function(questionId, downloadUrl){
check(questionId, String);
check(downloadUrl, String);
questionsList.update({_id: questionId},
{$set: {
picUrl: downloadUrl
}
});
}, //end upload image
Relevant server-side directive (minus file restriction):
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;
}
});
relevant mobile_config.js accessrules:
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/*');
relevant template to display pic:
{{#if theQuestion.picUrl}}
<img src="{{theQuestion.picUrl}}" width="300px" height="300px" class="userPic">
{{/if}}
relevant template to upload pic:
<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>
file restriction:
Slingshot.fileRestrictions("uploadFiles", {
allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited)
});
Encountered the same issue and I what I found is this. File object that we create using Webkit is different from the file Object that is available on Andriod. File Object constructor on Webkit is
Where as on Cordova it is different, to resolve the issue when using 'uploader.send' instead of passing a file object (Which internally been created by Meteor/Cordova) pass Blob object directly, the code which I used to create the blob object is
And the way I passed finally constructed my code is