why this code is not working for file download through api gateway in pdf format....could you please answer this

0

try { const headObject = await s3.headObject(params).promise(); const fileSize = headObject.ContentLength;

const readStream = await s3.getObject(params).promise()//.createReadStream(); console.log(readStream) //const fileContent = readStream.Body.toString('utf-8');

// Set headers for the response const headers = { //'Content-Length': fileContent, 'Content-Type': 'application/pdf', //'Content-Disposition': attachment; filename=${key}, 'Accept': 'application/pdf' //'application/octet-stream' }; const imageBuffer = Buffer.from(readStream.Body); const imageBase64 = await base64.fromByteArray(imageBuffer).toString('utf-8'); console.log(imageBase64)

const response={ statusCode: 200, headers, body: imageBase64//readStream//.toString("base64"), //isBase64Encoded: true, }; //const str = await response.body.transformToString(); //console.log(response) return response // Pipe the S3 object stream to the response //readStream.pipe(callback.response); } catch (error) { console.error(error); // callback(error); }

}; exports.handler=handle

1개 답변
1

What errors are you getting? Did you take in count the limitations of payload size for Lambdas and API Gateway?

답변함 일 년 전

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

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

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

관련 콘텐츠