spring - Java : How to accommodate special characters in the filename while uploading and downloading the file? -


Background:

I have a file that I am uploading The file link is stored in the database and not the actual file, the acetal file is stored in the file system, which is currently stored in my local machine.

Target:

My goal is to upload a file and download the file properly, which has special characters - #, $, %, @ Etc .

Problem:

I am able to upload files with special characters, but I am not able to download a special file. Apart from this, I can not make any changes in the Download Servlet because it is part of the framework , so the code I can do is upload servlet , So my attention is to upload a file with special characters in this way so that I can download them.

I have tried to create a nickname for the file name in which the special code has been moved to the place of the '_' symbol, this approach works fine and The file is capable of downloading, but the actual name is not maintained in the file, all the special characters in the file name are replaced with the '_' symbol and it is not acceptable because the user Be the real name needed.

Any suggestion or perspective:

Code:

  Save public models and views (HTTPSArlet request request, HTTP server response Feedback, object command, model endview model view, bind expense errors) throws exception {string newFileName = checkForSpecialCharsAndGetNewFileName (file.getOriginalFilename ()); System.out.println ("alias file name =" + newfilename); String url = "f" + (string.valuef (system synttime milliseconds)) "+" + newFileName; String filename = file.getOriginalFilename (); System.out.println ("Filename" + Filename); } // code to replace all the special characters in the file that comes with the '_' symbol Private String Checkerational Chars andgateNameFileName (String BasicFilename) {Final string [] splchars = {"#", "+", "$" }; String newString = root filename; (Int i = 0; i & lt; splChars.length; i ++) newString = StringTools Place (new string, splashar [ii], "_"); New string return; }  

Hopefully something is making sense here.

Thanks

If I understand you correctly, The names want to encode such as when you upload it, and download it later, you want to find the same file by file name.

To do this, you can use and classes.

You can do something like the following:

  string filename; FileName = URLEncoder.encode ("My String #", "UTF-8");  

He must change it in symbolic terms. To get the original file name:

  string originFilename = URLDecoder.decode (filename, "UTF-8");  

You can use the encoded file name to download the file from the service. Then you can decode the file name to properly store it.

Hope that helps.


Comments