ms-dred
@ms-dred
Вечно что то не то и что то не так...

Как загрузить gif в паблик по api.vk?

Подскажите в чем дело.
Получаю ссылку на загрузку документов и отправляю гифку по ней
{ 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);

        });

}
  • Вопрос задан
  • 1494 просмотра
Решения вопроса 1
Negezor
@Negezor
Senior Shaurma Developer
VK IO
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);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы