Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank PDF download via aws-sdk-go #4697

Open
hippiepaws opened this issue Jan 23, 2023 · 0 comments
Open

Blank PDF download via aws-sdk-go #4697

hippiepaws opened this issue Jan 23, 2023 · 0 comments
Assignees
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue

Comments

@hippiepaws
Copy link

hippiepaws commented Jan 23, 2023

Describe the bug

I'm trying to download a pdf saved on s3, serving it via a lambda written in go, with API Gateway on top of it. While the file on S3 has 15 pages and a lot of content, files being downloaded are coming out blank. The number of pages are recorded correctly, but the content is missing. The code looks like this:

func GetMenu(req events.APIGatewayProxyRequest, tableName string, dynaClient dynamodbiface.DynamoDBAPI, downloader *s3manager.Downloader) (
	*events.APIGatewayProxyResponse, error,
) {

bucket := "my_bucket"
	item := "file.pdf"
	file := aws.NewWriteAtBuffer([]byte{})
	_, err := downloader.Download(file,
		&s3.GetObjectInput{
			Bucket: aws.String(bucket),
			Key:    aws.String(item),
		})
	if err != nil {
		log.Fatalf("Unable to download item %q, %v", item, err)
	}
	file_bytes := file.Bytes()
	resp := events.APIGatewayProxyResponse{Headers: map[string]string{
		"Content-Type": "application/pdf", "Content-Length": strconv.Itoa(len(file_bytes)), "Content-disposition": "inline", "filename": item,
	}}
	resp.StatusCode = http.StatusOK
	resp.IsBase64Encoded = true

	resp.Body = base64.RawStdEncoding.EncodeToString(file.Bytes())
	return &resp, nil
}

Expected Behavior

The file should come with all the correct content

Current Behavior

File is either coming out to be an empty file or in a not supported PDF format when encoding it to base64, while keeping the API Gateway Binaries on.

Reproduction Steps

Put a file on S3
Write the above code for lambda and upload .zip file.
Attach an API Gateway on top of it to trigger lambda.
Hit the API Gateway url via a browser.

Possible Solution

Unable to figure it out

Additional Information/Context

No response

SDK version used

both v2 and v1

Environment details (Version of Go (go version)? OS name and version, etc.)

1.18

@hippiepaws hippiepaws added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 23, 2023
@RanVaknin RanVaknin self-assigned this Feb 13, 2023
@RanVaknin RanVaknin added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 13, 2023
@RanVaknin RanVaknin added the p2 This is a standard priority issue label Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants