Я не могу загрузить gif, превышающий лимит 5 МБ, и видео в Twitter с помощью node.js. - PullRequest
0 голосов
/ 18 декабря 2018

Я использую Twitter API для загрузки произвольного GIF с этим кодом, я хотел бы иметь возможность загружать GIF размером более 5 МБ и видео с использованием метода загрузки по частям, но я не могу найти какой-либо код, который, кажется, работает в Интернете идаже не пытаясь изо всех сил до сих пор.Может ли кто-нибудь помочь мне?Спасибо.

var fs = require('fs'),
path = require('path'),
Twit = require('twit'),
config = require(path.join(__dirname, 'config.js'));

var T = new Twit(config);

function random_from_array(images){
return images[Math.floor(Math.random() * images.length)];
}

function upload_random_image(images){
console.log('Opening an image...');
var image_path = path.join(__dirname, '/images/' + random_from_array(images)),
    b64content = fs.readFileSync(image_path, { encoding: 'base64' });

console.log('Uploading an image...');

T.post('media/upload', { media_data: b64content }, function (err, data, response) {
if (err){
  console.log('ERROR:');
  console.log(err);
}
else{
  console.log('Image uploaded!');
  console.log('Now tweeting it...');

  T.post('statuses/update', {
    media_ids: new Array(data.media_id_string)
  },
  function(err, data, response) {
      if (err){
        console.log('ERROR:');
        console.log(err);
      }
      else{
        console.log('Posted an image!');
      }
    }
  );
}
 });
}

fs.readdir(__dirname + '/images', function(err, files) {
  if (err){
console.log(err);
}
  else{
    var images = [];
   files.forEach(function(f) {
  images.push(f);
});

setInterval(function(){
  upload_random_image(images);
}, 1800000);
 }
});
...