E
E
Eugene2019-02-27 09:24:55
In contact with
Eugene, 2019-02-27 09:24:55

How to upload a picture to VK using the https module?

There is an implementation of uploading files to VK using the request module. How to do the same using the standard https module?

const fs = require('fs');
const request = require('request');

const url = 'https://pu.vk.com/c638131/upload.php?_query=eyJhY3QiO...';
const formData = {
    photo: fs.createReadStream('test.jpg'),
};

request.post({url, formData}, (error, httpResponse, body) => {
    if (error) {
        return console.error(error);
    }

    console.log(body);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Shatokhin, 2019-02-27
@iShatokhin

const https = require('https');
const agent = new http.Agent({});
const options = {
// method
// url => {
//    protocol
//   hostname
// }
// headers
// body
};
agent.request(options, cb);

Something like this (options will have to be formed by you). Question - why write a bicycle?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question