Created
January 13, 2019 22:17
-
-
Save ejnshtein/31d908cf7639be331e9c4ca0c9bdccb8 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment