Created
January 13, 2019 22:17
-
-
Save ejnshtein/31d908cf7639be331e9c4ca0c9bdccb8 to your computer and use it in GitHub Desktop.
Revisions
-
ejnshtein created this gist
Jan 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ const FormData = require('form-data') async function uploadFile (file) { const form = new FormData() form.append(`data`, file.file, { filename: file.name }) const res = await new Promise((resolve, reject) => { form.submit('https://telegra.ph/upload', (err, res) => { let data = '' res.on('data', chunk => data += chunk ) res.on('end', () => resolve(JSON.parse(data))) res.on('error', reject) }) }) return res }