dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
6k stars 1.14k forks source link

Uploaded image isn't in the right format #1062

Closed Androz2091 closed 4 years ago

Androz2091 commented 4 years ago

Hello, I'm trying to send images via this package and I'm getting the following error:

(node:59294) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/direct_v2/threads/broadcast/configure_photo/ - 400 Bad Request; Uploaded image isn't in the right format
    at Request.handleResponseError (/Users/simon/Documents/GitHub/pronote-bot/node_modules/instagram-private-api/dist/core/request.js:121:16)
    at Request.send (/Users/simon/Documents/GitHub/pronote-bot/node_modules/instagram-private-api/dist/core/request.js:50:28)
    at async DirectThreadRepository.broadcast (/Users/simon/Documents/GitHub/pronote-bot/node_modules/instagram-private-api/dist/repositories/direct-thread.repository.js:176:26)
    at async DirectThreadEntity.broadcast (/Users/simon/Documents/GitHub/pronote-bot/node_modules/instagram-private-api/dist/entities/direct-thread.entity.js:157:26)
    at async DirectThreadEntity.broadcastPhoto (/Users/simon/Documents/GitHub/pronote-bot/node_modules/instagram-private-api/dist/entities/direct-thread.entity.js:82:16)
    at async InstaUser.sendImage (/Users/simon/Documents/GitHub/pronote-bot/instagram/InstaUser.js:27:9)
(node:59294) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:59294) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

In another place in my code, I send images with another format and it works. I saw this issue: #661, but it didn't help me... How can I fix this?

Nerixyz commented 4 years ago

Could you link your image and possibly the debug output

Androz2091 commented 4 years ago

Here is the image: 27-au-31-janvier-2020 Actually it will be complicated to get debug logs, but if it's necessary I could send them to you...

Nerixyz commented 4 years ago

It's a png file, which isn't supported by Instagram (the API, not the app). You have to convert it to a JPEG file. You can do this in memory with e.g. png-to-jpeg or jimp.

Androz2091 commented 4 years ago

That's weird because in another place in my code I send png images... But, I converted it to a Buffer before, maybe that's why it's working?

Androz2091 commented 4 years ago

Oh, I see. I wrote images as png but the real extension is jpg.

Androz2091 commented 4 years ago

It works!! Thank you!