kombat
kombat

Reputation: 343

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.

Upvotes: 7

Views: 2238

Answers (3)

Gene
Gene

Reputation: 11285

I was getting that error when I tried the Eclipse browser. When I tried my code on Chrome, the FormDataContentDisposition.getFileName() was fine.

Upvotes: 0

slartidan
slartidan

Reputation: 21598

  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.

Upvotes: 3

Drifter64
Drifter64

Reputation: 1123

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.

Upvotes: 2

Related Questions