Background
The Location field returned by createFile() in index.js currently uses raw params.Key without URL encoding. This is pre-existing behavior that should be improved to properly handle filenames with special characters (e.g., spaces, parentheses).
Problem
Filenames with spaces or special characters (e.g., my file (1).txt) produce technically malformed URLs in the Location field:
- Current:
https://bucket.s3.region.amazonaws.com/my file (1).txt
- Expected:
https://bucket.s3.region.amazonaws.com/my%20file%20(1).txt
Solution
Apply proper URL encoding to params.Key when constructing the Location URL, using:
params.Key.split('/').map(encodeURIComponent).join('/')
This matches the logic already used in getFileLocation() and avoids encoding path separators.
References
Background
The
Locationfield returned bycreateFile()inindex.jscurrently uses rawparams.Keywithout URL encoding. This is pre-existing behavior that should be improved to properly handle filenames with special characters (e.g., spaces, parentheses).Problem
Filenames with spaces or special characters (e.g.,
my file (1).txt) produce technically malformed URLs in theLocationfield:https://bucket.s3.region.amazonaws.com/my file (1).txthttps://bucket.s3.region.amazonaws.com/my%20file%20(1).txtSolution
Apply proper URL encoding to
params.Keywhen constructing theLocationURL, using:This matches the logic already used in
getFileLocation()and avoids encoding path separators.References
Readablestream #459Readablestream #459 (comment)