0

I've the following ts code that submit a file came from GraphQL API to my AWS S3 bucket. it works perfectly when I run the project using nodejs http lib, but when I run it using sls offline start or from aws lambda function it uploads the file but it doesn't open(like a damaged file) - except text files.

the code:

const fileStream = data.createReadStream()
const uploadParams = {
                Bucket: 'XXX',
                Key: data.filename,
                Body: fileStream,
                ContentType: data.mimetype,
                ContentEncoding: data.encoding,
                ACL: 'public-read',
};
const result = await s3.upload(uploadParams).promise()

data object looks like this:

{ filename: '11083626_830419647032756_2338667058698516671_n.jpg',
  mimetype: 'image/jpeg',
  encoding: '7bit',
  createReadStream: [Function: createReadStream] }

I've tried converting the createReadStream to buffer and use s3.putObject() function instead but still not working.

Added the following configrations to allow binary files in serverless.yml but still the same problem:

provider:
    apiGateway:
        binaryMediaTypes:
            - '*/*'
AmrAnwar
  • 59
  • 1
  • 8

1 Answers1

0

after adding:

provider:
    apiGateway:
        binaryMediaTypes:
            - '*/*'
  • or instead of '/' in my case only 'multipart/form-data'

it worked in lambda AWS after making deploy, but still not working offline using sls offline start it might be a bug in their code or I should add additional thing to let it work offline

AmrAnwar
  • 59
  • 1
  • 8