Image getting corrupted while uploading to S3 via REST API deployed to AWS Lambda

0

I have an endpoint in my REST API developed in ASP.NET Core Web API and deployed to AWS Lambda which is responsible to upload image in AWS S3.

When I run the API locally it's able to upload the image successfully and when I downloading the same image from S3 it shows correctly in image viewer app.

But when I deploy the REST API to AWS Lambda and use the same API endpoint to upload the image we get 200 OK response from the API but when I download the same image from S3 it says the image is corrupted and gives below error.

What could be the possible reason that my API returns 200 OK for image upload but actually it doesn't upload successfully.

Image_error

C# code to upload image.

` var file = Request.Form.Files[0];

var BucketName = bucketName;

            using (var fileTransferUtility = new TransferUtility(_s3Client))
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadRequest = new TransferUtilityUploadRequest
                    {
                        InputStream = stream,
                        BucketName = BucketName,
                        Key = file.FileName,
                        ContentType = 
                        GetFileExtension(file.FileName) == "jpg" ? "image/jpeg" 
                                    : GetFileExtension(file.FileName) == "png" ? "image/png" : "image/jpeg" // Set the correct Content-Type here
                    };
                    await fileTransferUtility.UploadAsync(uploadRequest).ConfigureAwait(false);
                }
            }

`

1개 답변
0
수락된 답변

This was resolved by doing the change in AWS API Gateway which was invoking AWS Lambda.

api_gateway_changes

Once changes we have deploy the API Gateway once again.

Atif
답변함 6달 전

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

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

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

관련 콘텐츠