T
T
Taylor_Superhero2016-05-11 10:26:18
Node.js
Taylor_Superhero, 2016-05-11 10:26:18

How to transfer a file using multipart in nodejs?

I'm trying to send a file to telegram, forming multipart via formData.

var formData = {
  custom_file: {
    value:  fs.createReadStream('D:/node/Telegram/class.jpg'),
    options: {
      filename: 'class',
      contentType: 'image/jpg'
    }
  }
};

request.post({url:myUrl, formData: formData}, function optionalCallback(err, httpResponse, body) {
  if (err) {
    return console.error('upload failed:', err);
  } else {
  console.log('Upload successful!  Server responded with:', body);
  }
});

After some thought, telegram replies
Server responded with: {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"}

Although the file is in place. I also tried to send a file through the "Restler" module, sending information about the file to the module via fs.stat. fs.stat itself adequately sees the file, but telegram returns the same error. I googled and didn't find any real solution. Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Sivkov, 2016-05-11
@Taylor_Superhero

Are you sure that in Telegram the file field is called custom_file?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question