I am using clever-cloud as an host and they have a s3 like service for storage of picture. I am trying to make a simple image upload using slingshot with it but somehow can’t manage to have it work.
Here is the code:
client side :
onUploadFile(e){
var uploader = new Slingshot.Upload("avatars");
uploader.send(e.target.files[0], function (error, downloadUrl) {
if (error) {
// Log service detailed response.
console.error('Error uploading', uploader.xhr.response);
alert (error);
}
else {
Meteor.users.update(Meteor.userId(), {$push: {"profile.files": downloadUrl}});
}
});
}
server :
let AWSAccessKeyId = Meteor.settings.AWSAccessKeyId ? Meteor.settings.AWSAccessKeyId : process.env.AWSAccessKeyId;
let AWSSecretAccessKey = Meteor.settings.AWSSecretAccessKey ? Meteor.settings.AWSSecretAccessKey : process.env.AWSSecretAccessKey;
Slingshot.fileRestrictions("avatars", {
allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited).
});
Slingshot.createDirective("avatars", Slingshot.S3Storage, {
bucket: "shillerz",
bucketUrl: "shillerz.cellar.services.clever-cloud.com",
acl: "public-read",
AWSAccessKeyId:AWSAccessKeyId,
AWSSecretAccessKey:AWSSecretAccessKey,
authorize: function () {
//Deny uploads if user is not logged in.
if (!this.userId) {
var message = "Please login before posting files";
throw new Meteor.Error("Login Required", message);
}
return true;
},
key: function (file) {
//Store file into a directory by the user's username.
var user = Meteor.users.findOne(this.userId);
return user.username + "/" + file.name;
}
});
Documentation for it is there : https://www.clever-cloud.com/doc/addons/cellar/
but it says you can use normal aws-sdk so I guess slingshot should work.
Only change I made was to set up a bucketUrl, was it the good one ?
Anyway, it gives me back a downloadUrl like that :
shillerz.cellar.services.clever-cloud.com/username/PictureName.jpg
where no picture can be found. I am a bit lost. Where is my picture ? where can I access it ? Can I check it was saved somewhere ?