S
S
Stanislav2017-01-04 20:34:11
In contact with
Stanislav, 2017-01-04 20:34:11

How to upload gif to public via api.vk?

Tell me what's the matter.
I get a link to download documents and send a GIF to it
{ error: 'unknown error' }

let config = require('../configs')
    , request = require('request')
    , fs = require('fs')
    , async = require('async');

async.waterfall([

    getUploadUrl,
    uploadFile

], (e) =>{

    if ( e ) console.log(e);

    process.exit();

});

function getUploadUrl(c) {

    let page = 'https://api.vk.com/method/docs.getWallUploadServer?access_token=' + config.vk.token;

    request.get(page, {'json': true}, (e, response, document) => {

        return c(null, document.response.upload_url);

    });

}

function uploadFile(page, c) {

    let data = {
        file1:fs.createReadStream('/file.gif')
    };

    request
        .post({
            url: page,
            formData: data,
            json: true
        }, (e, r, d) => {

            console.log(r);

            return c(e, d);

        });

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2017-01-04
@ms-dred

VKIO

const { VK } = new require('vk-io');

const vk = new VK();

vk.setOptions({...});

vk.upload.document({
  group_id: 1234,
  source: __dirname + '/file.gif'
})
.then((doc) => {
  console.log('Success upload', doc);

  /* ...code */
})
.catch(console.error);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question