Snow Snow - 6 months ago 19
HTML Question

URL encode/decode on file name replace spaces with +, need alternative.

My product is a web application.

I have files that I upload and download later on, to/from my server.

I am using when uploading files with unicode characters and when downloading files in order to save the file name and finally return it to the client as expected with no question marks and stuff (?????) .

The problem is that if the file name consists spaces then the encode/decode replace them with + character which is perfectly normal because that's their business implementation, but clearly as you can understand it does not fit to my purpose.

The question is what alternative do I have to overcome this situation?

Is there build-in method for that or 3rd party package?


I found the cure!
I was just needed to use for that:

public static String encode(String urlString) throws UnsupportedEncodingException
        URI uri = new URI(urlString);
        return uri.toASCIIString();
    catch (URISyntaxException e)

The toASCIIString() escapes the special characters so when the string arrives to the browser it is shown correctly.