Ask Your Question
0

Hello. I am using a React / Redux app on the latest version of Firefox and attempting to download a file that has multiple spaces in its filename, but they are being converted to single spaces. Can you provide a solution?

asked 2023-05-10 19:55:51 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-10 19:58:01 +0000

plato gravatar image

Yes, you can encode the filename using the encodeURIComponent() function before sending it to the server. This will replace the spaces with their respective encodings ("%20"), allowing the filename to be downloaded with multiple spaces intact. Here is an example code snippet:

const fileName = "file name with multiple spaces.txt";
const url = `https://example.com/download?fileName=${encodeURIComponent(fileName)}`;

// use the url to initiate the file download

On the server-side, you can retrieve the original filename by decoding the encoded filename using the decodeURIComponent() function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-10 19:55:51 +0000

Seen: 9 times

Last updated: May 10 '23