2012-04-21 32 views
23

Por lo tanto, estoy tratando de escribir un método que realiza una llamada http. Cuando ejecuto el método, me sale el siguiente error:El método Meteor.http no está definido en el servidor?

Exception while invoking method 'upload' TypeError: Cannot call method 'call' of undefined

Aquí es lo que el código es el siguiente:

Cliente:

console.log(Meteor.call('upload', f, content)); 

Servidor:

Meteor.methods({ 
    upload: function(file, content) { 
    this.unblock(); 
    Meteor.http.call("PUT", "http://blah"); 
    } 
}); 

ACTUALIZACIÓN : Problema resuelto, resulta que tuve que habilitar el paquete: meteor add http

+0

La expresión * * 'Meteor.http' evalúa a indefinido ... ¿Dónde está el problema/pregunta? Una pregunta sería: "¿Por qué Meteor.http no es una función?" o algo así. Esto es solo depuración.) –

+0

http://docs.meteor.com/#meteor_http_call –

+0

¿Hay algún error en la consola de su navegador? –

Respuesta

40

Usted sólo tendrá que añadir el paquete HTTP ejecutando en esta línea de comandos en su proyecto:

meteoro añadir http

+0

Intenté esto ... todavía me está dando el error de que Meteor.http no está definido. –

3

también necesita una llamada usando el lado del cliente Meteor.call.

De la documentación:

On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn't have fibers, so there is not actually any way it can block on the remote execution of a method.

por lo que debe cambiar esta

console.log(Meteor.call('upload', f, content)); 

a este

Meteor.call('upload', f, content, function(error, result){console.log(result);}); 
Cuestiones relacionadas