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

fix fileName - undefined and fileType not present in s3 upload objects #5680

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

qxprakash
Copy link

@Murderlon while trying to reproduce and fix #5666 , #5667

I came across this bug , where uploading a file from the example code provided at examples/aws-nodejs/public/index.html
resulted in uploaded files with undefined_name in instead of fileName in the S3 key as well as no fileType present

reference -

image

this was because while making the request to /s3/params to get the signed URL , it parses the fileName and contentType from the request body to append it to the Key

const signOnServer = (req, res, next) => {
// Before giving the signature to the user, you should first check is they
// are authorized to perform that operation, and if the request is legit.
// For the sake of simplification, we skip that check in this example.
const Key = `${crypto.randomUUID()}-${req.body.filename}`
const { contentType } = req.body
getSignedUrl(
getS3Client(),
new PutObjectCommand({
Bucket: process.env.COMPANION_AWS_BUCKET,
Key,
ContentType: contentType,
}),

but in default case (without the customEndpoint) it's a GET request which causes this error as we're trying to parse the fileName and contentType from req body ,

const query = new URLSearchParams({ filename, type, ...metadata } as Record<
string,
string
>)
return this.#client.get(`s3/params?${query}`, options)
}

After :

image

File uploaded with correct fileName and correct fileType

@qxprakash qxprakash marked this pull request as ready for review March 9, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AwsS3 multipart with custom endpoints doesn't work with files <5 mb
1 participant