Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Created November 16, 2021 08:11
Show Gist options
  • Save Tanapruk/0940f7f6d4763ed3920739a5275fac3d to your computer and use it in GitHub Desktop.
Save Tanapruk/0940f7f6d4763ed3920739a5275fac3d to your computer and use it in GitHub Desktop.
axios in node.js call line notify to send image
// # Requirement
// * `npm i form-data`
// # Test on node 14
--
import axios from 'axios'
import * as fs from 'fs'
import * as FormData from 'form-data'
const imageFile = fs.createReadStream('./screen1.png')
const formData = new FormData()
formData.append('message', 'hello from line notify')
formdata.append('imageFile', imageFile)
const result = await axios({
method: 'POST',
url: 'https://notify-api.line.me/api/notify',
headers: { Authorization: `Bearer ${token}`, 'content-type': 'multipart/form-data', ...formData.getHeaders() },
data: formData
})
//reference:
// * https://notify-bot.line.me/doc/en/
// * https://masteringjs.io/tutorials/axios/axios-multi-form-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment