mywork / lib /upload.js
DeeCeeXxx's picture
Upload 199 files
6c07b9a verified
const fs = require('fs')
const chalk = require('chalk')
async function uptotelegra (Path) {
return new Promise (async (resolve, reject) => {
if (!fs.existsSync(Path)) return reject(new Error("File not Found"))
try {
const form = new FormData();
form.append("file", fs.createReadStream(Path))
const data = await axios({
url: "https://telegra.ph/upload",
method: "POST",
headers: {
...form.getHeaders()
},
data: form
})
return resolve("https://telegra.ph" + data.data[0].src)
} catch (err) {
return reject(new Error(String(err)))
}
})
}
global.uptotelegra = uptotelegra