Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only the filename with Jersey File Upload

I'm doing a file upload with Jersey, but I need only the filename. Internet Explorer sends the entire path, and based on what's in FormDataContentDisposition, Jersey parses out the slashes, so I can't even parse that. Thanks.

like image 679
kombat Avatar asked Oct 03 '13 16:10

kombat


2 Answers

Sounds like a difficult issue. The ideal case of course is to grab the string containing the slashes and just use string.split!

Failing that, the only strategy i can begin to think of is to try iterating through the string seeing if folders exist for various lengths of the first part of the string etc. This can cause problems too though if you intend to find a folder "MyFolder (2)" and theres also a "MyFolder". I don't know alot about jersey but i would recommend trying to find a different way to grab the string you need.

like image 155
Drifter64 Avatar answered Nov 05 '22 21:11

Drifter64


  1. Add a change event to the file input tag
  2. Parse out the filename as it still has slashes at this point
  3. Stick that value into a hidden input

That hidden input then gets submitted along with the rest of the form.


@kombat has found this solution and posted it as a comment. For better this is now reposted as a community wiki answer.

like image 35
slartidan Avatar answered Nov 05 '22 23:11

slartidan