1

I tried following the document: https://developers.line.me/en/docs/messaging-api/reference/#get-content

I tried get by Postman, i got image success. But I want get by lambda function use line/bot-sdk. My code:

      //get image send by user
  var http = require("https");

  var options = {
    method: "GET",
    hostname: "api.line.me",
    path: "/v2/bot/message/8073497242123/content",
    headers: {
      "Authorization": "Bearer 99GP35mAU2+OF4L4RYM92h9+Hbfm11TBwNG7vP9uIthDGgWbcnx8JYH5kWgEQYQDJliCCLZOvIOLblrX8kBq60F5XsK1JHBs/LDXrv1GUTH4OzabVjWigJW9akRhkF5j53EgxwYL1fNXJoyvDQsE6AdB04t89/1O/w1cDnyilFU=",
    }
  };

  var req = http.request(options, function (res) {
    var chunks = [];

    res.on("data", function (chunk) {
      chunks.push(chunk);
      console.log(chunks);
    });

    res.on("end", function () {
      var body = Buffer.concat(chunks);
      console.log(body);
    });
  });

  req.end();

But when I check response on AWS Cloudwatch, it does not return any data

Nam Lee
  • 891
  • 1
  • 9
  • 20

1 Answers1

0

I log data image on aws cloudwatch success. But it is format:

<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 00 48 00 00 ff e1 00 58 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 02 01 12 00 03 00 00 00 01 00 01 ... >
<Buffer d6 aa 99 49 eb 4c dd 4c 0b 82 4e 37 55 9b 7c b1 dc 6b 29 5b 2d b4 56 bd bb 05 e0 f7 aa 19 a2 ae 46 00 a7 4a c5 90 aa f5 35 00 61 9c 0a 94 0c 10 0d 32 ... >
.......

How to convert to image :(

Nam Lee
  • 891
  • 1
  • 9
  • 20
  • I thought it's nodejs issue instead of AWS. how about try to see the result of `JSON.stringify(body) ` ? – kakashi Jun 06 '18 at 23:46
  • I got success image. I'm using file = fs.createWriteStream("file.jpg") and pipe(file). However, it will be fixed at file extension "jpg". For example, the file I get has the extension "gif", it will still save in the format "jpg". – Nam Lee Jun 07 '18 at 10:02
  • so it looks to me that you are able to convert the binary to picture. I thought you can check image metadata to differentiate gif or jpg. There is a package you can check it out https://github.com/sindresorhus/file-type – kakashi Jun 07 '18 at 11:41
  • @kakashi thank you, i can get image format via headers["content-type"] – Nam Lee Jun 08 '18 at 04:31