Answer the question
In order to leave comments, you need to log in
Node.js POST request to upload a VKontakte file via Open API?
I can't figure out what fields I need to send to the contact so that he returns the photo to me. At the moment, a response is being returned to me, but the photo field is empty.
1) VKontakte about uploading a photo to the user's wall here
2) I tried different modules for the post request (including the standard http.request), but so far settled on - superagent . A little lower there is documentation on Attaching files.
3) my piece of code
var request = require('superagent');
...
request
.post(url)
.set('Content-Type', 'multipart/form-data')
.set('Content-Length', Buffer.byteLength(dataCL,'utf8'))
.attach('filename',memsPath+img+'.jpg')
.field('photo',img+'.jpg')
.end(callbackSA);
status 200
'{"mid":10393237,"gid":0,"server":425122,"photo":"","hash":"e65dc1750b1b02ae815bca319b0884be"}'
Answer the question
In order to leave comments, you need to log in
madmages - picking the source code into your hands ...
but in fact - the super agent itself, inside it already transfers the file to the stream, and writes it, but alas, it does not put down the content-length, which is so necessary for the VK api.
After looking at the options, I implemented the request through node-curl, the
final solution looks something like this:
curl(url, {
MULTIPART: [
{name: 'file1', file: 'path/to/img.png', type: 'image/png'},
{name: 'sumbit', contents: 'send'}
]
}, function(e) {
log.info(this.body);
res.json(this.body);
});
And that's not going to work?
request
.post(url)
.set('Content-Type', 'multipart/form-data')
.set('Content-Length', Buffer.byteLength(dataCL,'utf8'))
.attach('photo',memsPath+img+'.jpg', img+'.jpg')
.end(callbackSA);
.set('Content-Type', 'multipart/form-data')
.set('Content-Length', Buffer.byteLength(dataCL,'utf8'))
request
.post(url)
.attach('photo',memsPath+img+'.jpg', img+'.jpg')
.end(callbackSA);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question