MRVDH / picnic-api

Unofficial and unaffiliated Node.js npm package as a wrapper for the API of the online supermarket Picnic.
MIT License
50 stars 7 forks source link

Image not working? #4

Closed Disane87 closed 3 years ago

Disane87 commented 3 years ago

HI, thank you for this great project! Currently I'm using your api for my project. Now I wanto to get the image of a product, but this isnt working:

app.get('/image/:imageid.:extension', cors(corsOptions), async (req, res) => {
  const imageID = req.params.imageid;
  const extension = req.params.extension;
  const image = await picnicClient.getImage(imageID, ImageSizes.LARGE);
  // const base64Image = new Buffer.from(image.toString('binary'), 'base64')
  // res.writeHead(200, {
  //    'Content-Type': `image/${extension}`,
  //    'Content-Length': image.length
  //  });

  res.set('Content-Type', `image/${extension}`);
  res.set('Content-Length', image.length);
  res.set('Image-ID', `image/${extension}`);

  return res.end(image);
})

In postman I only get this: image

Am I doing it wrong?

MRVDH commented 3 years ago

Correct, the api sends a request with some incorrect headers. This needs to be fixed, which I will do soon, thanks for reporting. 👍

If you want a temporary fix you can send a request like this: 'https://storefront-prod.nl.picnicinternational.com/static/images/IMAGE_ID/SIZE.png'. Example: 'https://storefront-prod.nl.picnicinternational.com/static/images/8560e1f1c2d2811dfefbbb2342ef0d95250533f2131416aca459bde35d73e901/medium.png' This is basically what the api does as well.

Disane87 commented 3 years ago

Thank you for investigation! Actually I load them by the url manually like you proposed :)

Kind regards from Germany 🇩🇪 to my beloved Dutchies

MRVDH commented 3 years ago

Got distracted, but fixed it just now in v1.4.2. 👍