Skip to content

Instantly share code, notes, and snippets.

@ejnshtein
Created January 13, 2019 22:17
Show Gist options
  • Save ejnshtein/31d908cf7639be331e9c4ca0c9bdccb8 to your computer and use it in GitHub Desktop.
Save ejnshtein/31d908cf7639be331e9c4ca0c9bdccb8 to your computer and use it in GitHub Desktop.
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