Multipart upload
I am trying to use node-curl to post an image to facebook's api, I have to use multipart/form-data as the content type because that is what their api expects. I thought node-curl would simplify this process, because facebook expects a simple curl request :
curl
-F '[email protected]'
-F 'access_token=___'
"https://graph.facebook.com/act_368811234/adimages"
I tried duplicating the multipart example, but it failed, and trying to get this module to tell me anything useful about what happened has been a nightmare... no examples on how to "Retrieve data from curl". status, body, and header are all undefined, I'm assuming because the request failed. But the request's error handler callback is not firing at all. Trying to call .info() on the object built by CurlBuilder mysteriously logs some more information (no idea how this is happening as I am passing no parameters to .info(), which should then immediately throw an error, which it does eventually, but it logs some stuff) and I have no idea what to pass it (tried 'RESPONSE_CODE' which failed). Here is my code for reference:
var nc = require('node-curl'); var curlReq = nc.create(); curlReq.open(); curlReq('https://graph.facebook.com/act_1374394842779617/adimages', { VERBOSE: 1, MULTIPART: [ {name: 'balloons.jpg', file: req.files.file.path, type: 'image/jpeg'}, {name: 'access_token', contents: accessToken, type: 'text/plain'} ] }, function(e) { console.log("ERROR!!!!"); console.log(e); console.log(this.body); this.close(); });
console.log(curlReq);
console.log(curlReq.status);
console.log(curlReq.body);
console.log(curlReq.curl_);
curlReq.close();
Here is my console's log:
{ [Function] perform: [Function], setDefaultOptions: [Function], log: [Function], setOptions: [Function], setopts: [Function],
- Closing connection #0 info: [Function], end: [Function], close: [Function], open: [Function], reset: [Function], create: [Function], get_count: [Function], id: 2, curl_: { options: {}, httppost: [ [Object], [Object] ], chunks: [], on_write: [Function], on_end: [Function], on_error: [Function], id: 1 }, defaultOptions: {}, running: true, url: 'https://graph.facebook.com/act_1374394842779617/adimages', options: { VERBOSE: 1, MULTIPART: [ [Object], [Object] ] }, debug: undefined, effectiveOptions: { VERBOSE: 1, MULTIPART: [ [Object], [Object] ] } } undefined undefined { options: {}, httppost: [ [ 0, <Buffer 62 61 6c 6c 6f 6f 6e 73 2e 6a 70 67>, 1, <Buffer 2f 76 61 72 2f 66 6f 6c 64 65 72 73 2f 68 67 2f 7a 7a 30 6a 36 62 64 39 32 64 62 35 6b 6b 73 76 71 35 6d 6d 6a 67 70 6d 30 30 30 32 37 39 2f 54 2f 30 35 ...>, 3, <Buffer 69 6d 61 67 65 2f 6a 70 65 67> ], [ 0, <Buffer 61 63 63 65 73 73 5f 74 6f 6b 65 6e>, 2, <Buffer 43 41 41 49 63 49 49 77 49 57 63 41 42 41 43 68 43 6f 77 35 53 4c 77 44 72 71 61 72 73 70 61 31 77 37 6f 5a 41 69 37 77 73 62 77 4c 7a 74 34 38 37 43 78 ...>, 3, <Buffer 74 65 78 74 2f 70 6c 61 69 6e> ] ], chunks: [], on_write: [Function], on_end: [Function], on_error: [Function], id: 1 }
Also, I don't know if you intended for other people to use this module, but the documentation and examples aren't very helpful. Needs to be way more detailed in exposing what's going on behind the scenes.
You close the curl before the request finished by code curlReq.close();. close should be in the callback function.