Meteor Amazon s3 delete image - meteor

I have successfully uploaded an image to amazon s3 with this meteor package
https://github.com/Lepozepo/S3 Now I am trying to delete the file, which I am getting a error on.
This is the documentation for the s3.delete code
S3.delete(path,callback)
This function permanently destroys a file located in your S3 bucket.
Parameters:
path: Must be in this format ("/folder/other_folder/file.extension").
So basically always start with "/" and never end with "/". This is
required.
callback: A function that is run after the delete operation
is complete returning an Error as the first parameter (if there is
one), and a Result as the second.
This is my upload and delete code
Template.postSubmit.events({
"click button.upload": function(){
var files = $("input.file_bag")[0].files
S3.upload({
files:files,
path:"uploads"
},function(e,r){
console.log(r);
delete_url = r.relative_url;
console.log(delete_url);
});
},
"click button.delete": function(){
S3.delete({
path:delete_url
},function(e,r){
console.log(e);
console.log(r);
});
}
});
The error I get when hitting the delete button.
errorClass {isClientSafe: true, error: 400, reason: "Match failed", details: undefined, message: "Match failed [400]", …}
details
:
undefined
error
:
400
errorType
:
"Meteor.Error"
isClientSafe
:
true
message
:
"Match failed [400]"
reason
:
"Match failed"
stack
:
"Error↵ at Connection._livedata_result (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:4823:23)↵ at onMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:3528:206)↵ at http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:2908:9↵ at Array.forEach (<anonymous>)↵ at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:149:11)↵ at SockJS.self.socket.onmessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:2907:43)↵ at SockJS.REventTarget.dispatchEvent (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:142:28)↵ at SockJS._dispatchMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1309:14)↵ at SockJS._didMessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1375:26)↵ at WebSocket.that.ws.onmessage (http://localhost:3000/packages/ddp-client.js?hash=14d966b7972bd95a1f7015fec9ac340f10508a44:1531:21)"
__proto__
:
Error
Update
This is the error I got on the server in terminal side
Exception while invoking method '_s3_delete' Error: Match error: Expected string, got object

You should call it like this:
S3.delete(delete_url, function() { ... });
First parameter should be url itself, not the object like in your example.

Related

JS: firebase.init error: TypeError: Cannot read property 'database' of undefined

Am getting this error after following the steps mentioned in the nativescript-plugin-firebase readme file.
JS: firebase.init error: TypeError: Cannot read property 'database' of
undefined
https://github.com/EddyVerbruggen/nativescript-plugin-firebase
but i dont really understand nor do i know how to solve that.
the version of the plugin am using is : 6.4.0
with tns 4.1.2
EDIT: init code, from app.js
var firebase = require("nativescript-plugin-firebase");
firebase.init({ persist: true
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function (instance) {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I finally solved it by installing the plugin manually via the CLI (i initially installed it through NativeScript sidekick) apparently they didnt take in count the fact that some plugins may require some user inputs, to do write specific config file (which nativescript-plugin-firebase), so by installing it manually i got to provide the user input needed, it got configured and it worked!

Polymer 1.x: $key throws error when saving to Firebase

I want to save a firebase-document to Firebase. But I encounter the following error.
error.log
Uncaught (in promise) Error: Firebase.push failed: first argument contains an invalid key ($key) in property 'xxxxxxxxxxxx.items'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"
Here is the relevant code.
my-element.html
<firebase-document id="document" ... ></firebase document>
...
save: function() {
var doc = this.$.document;
console.log('Saved', doc.data);
return doc.save(this.itemsPath).then(function() {
console.log('Saved:', doc);
doc.reset();
}.bind(this));
return Promise.resolve();
},
The data object contains a key label containing the $ character. But this is automatically introduced by Firebase, not a programming decision.
console.log
Saved: {
$key: "foo" // This is the object key in Firebase
...
}
What edits can I make to save my data?

Meteor audit-argument-checks

I have a Meteor project where I'm using audit-argument-check. I'm getting an error message
Error: Did not check() all arguments during publisher 'document
I'm know this is related the audit-argument-check not being able to check all arguments. But as far as I'm concerned, I checked all of them. Concrete, I have defined a collection 'documents' and attached a SimpleSchema. As part of iron-router, I have the following:
Router.route('customerDocumentShow', {
template: 'customerDocumentShow',
path: 'customer/documents/:_id',
waitOn: function () {
return Meteor.subscribe('document', this.params._id);
},
data: function () {
return Documents.findOne(this.params._id);
}
});
So I'm passing only the documentId (this.params._id). On the server, I have defined a method:
Meteor.methods({
documentsReadMethod: function(documentId){
check(documentId, String);
var documentItem = Document.findOne(argument);
if (!documentItem) {
throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.');
}
return documentItem;
}
});
So I'm checking to documentId in the server method. So not sure why I'm getting this error message.
Note: One thing I'm not entirely sure about though is how I need to call this method (right now, it's documentsReadMethod_. I'm not explicitly calling (on the client):
Meteor.call(documentsReadMethod, this.params_id);
as I'm using autoform, collection2 and simpleschema. I've been spending the entire weekend, but have no clue. Any idea's ?
Note: the code is on github: https://github.com/wymedia/meteor-starter-base
The problem is in the publish. You didn't check the id here:
https://github.com/wymedia/meteor-starter-base/blob/master/server/publications/documents.js#L16
Just add check(id, String); line 16 and it should work.
I have the same problem with another tuto !
Answer found at check is not defined in meteor.js : since Meteor v1.2, you have to add this package:
$ meteor add check

Meteor Iron:Route with Meteor 1.2

I'm learning Meteor by following this tutorial.
Here is my git https://github.com/nicholaschong12/meteor-slackclone
I'm getting this error:
Uncaught TypeError: Cannot read property 'channel' of undefined
Uncaught TypeError: Function.prototype.apply: Arguments list has wrong
type
Meteor.startup(function(){
Session.set('channel',this.params.channel);
});
Please help me to understand this error.
Thank You
Looking at the error:
Uncaught TypeError: Cannot read property 'channel' of undefined
We can see that it is trying to read a property 'channel' of an undefined object. This object from your code is:
this.params
Reading the iron:router docs, tells us that:
When a user goes to that url, the actual value of the parameter will be stored as a property on this.params in your route function.
However in the code snippet you provided:
Meteor.startup(function(){
Session.set('channel',this.params.channel);
});
You are trying to access this.params inside a Meteor.startup callback function, not a Router.route function. In this context this.params is undefined, as the error is telling you.
Change your startup code to match the tutorial:
Meteor.startup(function() {
Session.set('channel', 'general');
});
And in your routing code you can use values from the route like this:
Router.route('/:channel', function () {
Session.set('channel', this.params.channel);
this.render('messages');
});
In this context this.params will return an object, including the channel property defined in the routes path.

db.collection.update() throws 'undefined is not a function'

I have this server side method (Meteor method) that successfully finds a document by the ID that it is passed, but when I go to issue a mongo .update(), I get an internal server error (500).
setToggle: function(detailId){
var checked_detail = detailsCollection.findOne({_id: detailId});
checked_detail.update({$set: {checkboxStatus: 'toggle'}});
}
Here is where I initially call the method on the client to create the document:
'submit form': function(ev){
ev.preventDefault();
var detailFormData = {
detail: $(ev.target).find('[name = detail]').val(),
parentId: $(ev.target).find('[name = parentId]').val(),
checkboxStatus: ''
}
Meteor.call('addDetail', detailFormData);
}
And here is that server insert method, so you can see the model:
addDetail: function(detailFormData){
if(! Meteor.userId()){
throw new Meteor.Error('not-authorized');
}
detailsCollection.insert({
detail: detailFormData.detail,
parentId: detailFormData.parentId,
checkboxStatus: detailFormData.checkboxStatus
});
}
Your update syntax is wrong : you're retrieving the Mongo document and then trying to call the update operation on the resulting plain JS object instead of calling the method on the collection itself.
Rewrite your code like this :
setToggle: function(detailId){
detailsCollection.update(detailId,{
$set: {checkboxStatus: 'toggle'}
});
}
The Mongo Collection update syntax takes two (mandatory) parameters :
a Mongo selector to identify which documents in the collection should be updated (on the client using minimongo you're only allowed to modify documents by _id).
a Mongo modifier object to specify how the matching documents should be modified.
https://docs.meteor.com/#/full/update

Resources