Skip to content

Instantly share code, notes, and snippets.

@clsung
Created April 16, 2021 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clsung/f1ca7aeb8e2474e8afd825c10a6038ad to your computer and use it in GitHub Desktop.
Save clsung/f1ca7aeb8e2474e8afd825c10a6038ad to your computer and use it in GitHub Desktop.
function handleImage(message, replyToken) {
axios.get(`https://api-data.line.me/v2/bot/message/${message.id}/content`, {
headers: {
'Authorization': `Bearer ${process.env.CHANNEL_ACCESS_TOKEN}`
}, responseType: 'stream'
}).then((res) => {
const tmp = tempfile();
const writer = fs.createWriteStream(tmp);
res.data.pipe(writer);
writer.on('finish', () => {
imgur.setAccessToken(`${process.env.IMGUR_ACCESS_TOKEN}`);
imgur
.uploadFile(tmp)
.then((json) => {
return client.replyMessage(replyToken, {
"type": "text",
"text": `${JSON.stringify(json)}`
});
})
.catch((err) => {
console.error(err.message);
});
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment