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.

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠