은승우

Update app.js

Showing 1 changed file with 15 additions and 4 deletions
......@@ -82,9 +82,20 @@ async function handleEvent(event) {
}
else if (event.type == 'message'&& event.message.type == 'image') {
return new Promise(async(resolve,reject)=>{
fs.writeFileSync('./photo/image.png',event.message.image)
client.getMessageContent(event.message.id)
.then((stream) => {
stream.on('data', (chunk) => {
const fs = require('fs');
const file = fs.createWriteStream('./photo/image.jpeg');
for(let i=0; i<= 1e6; i++) {
file.write(chunk);
}
file.end();
});
});
var cheerio = require('cheerio');
var file=fs.readFileSync('./photo/image.png');
var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr';
var options = {
uri: uriBase,
......@@ -94,10 +105,10 @@ async function handleEvent(event) {
language: 'en'
},
headers: {
'Content-Type': 'application/octet-stream',
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc'
},
body: file
body: fs.readFileSync('./photo/image.jpeg')
};
request.post(options, function (error, response, body) {
......