api gateway binary data

0

This question relates to https://repost.aws/questions/QUEPFLM_x_SJaZNkBJ-pYYPg/upload-jpeg-to-lambda where no satisfactory answer was provided.

I have created a working example of an image download, reachable here:

https://xmv92e5ly4.execute-api.eu-west-2.amazonaws.com/prod/upload

This end point will correctly return a binary image. The lambda source code is pretty simple:

const fs = require('fs')
exports.handler = async (event) => {
    // TODO implement
    console.log(fs.readdirSync('/mnt/data/uploads'));

    const response = {
        statusCode: 200,
        isBase64Encoded: true,
        headers: {
            'Content-Type': 'image/jpeg'
        },
        body: fs.readFileSync('/mnt/data/uploads/small_biometriclogin_1a968aa583.jpg').toString('base64')
    };
    return response;
};

On the api gatway side, i did pretty much nothing except for entering */* as Binary Media Types.

My questions are:

  1. why does the code above stop working if i put as Binary Media Types image/jpeg, or anything other than */* (image/* for example)?

  2. a similar set up (end point reachable here https://apigwtest.punch-in.co.uk/uploads/small_biometriclogin_1a968aa583.jpg), with Binary media types set to / returns only text, no binary.

Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen