Created
November 16, 2021 08:11
-
-
Save Tanapruk/0940f7f6d4763ed3920739a5275fac3d to your computer and use it in GitHub Desktop.
axios in node.js call line notify to send image
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
// # 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