express icon indicating copy to clipboard operation
express copied to clipboard

Doesn't return a file with special characters %23, %2A, etc.

Open charlyalize opened this issue 7 months ago • 1 comments

Doesn't return a file with special characters %23, %2A, etc. I'm working on a Node.js project to download files with names like: normal_00dc038225ac0372_cpd_%2A%23%2A00936154844019_19619_19119_18-53-44_2025-05-20-019B0282-10063123-00000001.mp3

and Express can't find it.

Incoming request: GET /audios/2025/05/21/normal_00dc038225ac0372_cpd_%2A%23%2A00936154844019_19619_19119_18-53-44_2025-05-20-019B0282-10063123-00000001.mp3

and returns 404 notfound, the file exists at the correct path.

charlyalize avatar May 21 '25 04:05 charlyalize

If you request /normal_00dc038225ac0372_cpd_%2A%23%2A00936154844019_19619_19119_18-53-44_2025-05-20-019B0282-10063123-00000001.mp3 then the server after decoding the URL will receive normal_00dc038225ac0372_cpd_*#*00936154844019_19619_19119_18-53-44_2025-05-20-019B0282-10063123-00000001.mp3. This is the result of URI/percent encoding (Wikipedia, RFC 3986)

If you have a file with % in name on disk, then you'll have to encode this character as %25 in URL. In JavaScript you can use encodeURIComponent to encode a single component of URI and decodeURIComponent to decode. % is a special character in URIs, because it is a marker of an encoded character.

You can check if I'm right by requesting /audios/2025/05/21/normal_00dc038225ac0372_cpd_%252A%2523%252A00936154844019_19619_19119_18-53-44_2025-05-20-019B0282-10063123-00000001.mp3 from your server, which should decode to the path that you want.

krzysdz avatar May 21 '25 06:05 krzysdz