2015-11-18 2 views
0

Я хочу, чтобы отправить документ в телеграмме, я написал код:Javascript отправить блоб телеграммы

function send(file) { 
    var formData = new FormData(); 
    formData.append('file', file, "2.txt"); 

    var xhr = new XMLHttpRequest(); 
    xhr.open('POST', 'https://api.telegram.org/bot' + token + '/sendDocument?chat_id=' + id, true); 

    xhr.send(formData); 
} 
var blob = new Blob(['hello'], {type: 'plain/text'}); 
console.log(blob) 
blob.lastModifiedDate = new Date(); 
blob.name = '2.txt'; 
send(blob); 

Telegramm ответ:

{"ok":false,"error_code":400,"description":"[Error]: Bad Request: there is no document in request"} 

ответ

0

Параметр Телеграмма ожидает файл, чтобы быть в назван document, а не file.

function send(file) { 
    var formData = new FormData(); 
    formData.append('document', file, '2.txt'); 

    // the rest of your code 
} 
+0

Это работает! Спасибо! –