• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help needed with MultipartRequest from O'Reilly.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I searched this forum and other ones but did not come across a solution to my problem and reading source code for the class did not help me either... I hope someone will help me figure this one out.
I have an application which uses the MultipartRequest class to upload files. To avoid name conflits I simply use the DefaultFileRenamePolicy object which appends 1, 2, 3 to file names... That works fine and I want to keep it this way. But my users will submit files with names containing non-ascii characters which are a problem for me. They also submit files with names as long as 100 chars.
I would like to intercept the upload process and rename the file myself somewhere along this logic:
1. Get file name submitted by user
2. Replace all non ascii chars to "_"
3. Cut file name to 25 chars
4. Force upload process to use the new file name as destination name.
5. Let DefaultFileRenamePolicy rename the file if one by that name exists.
I need help understanding where this interception should take place. I am not asking how to replace a character in string or how to cut the file to 25 chars.
Can anyone help?
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jacek
u can probably put that interception before u use MultipartRequest object and pass the request to it.
now, here u'll have to modify the request object so to say (because MultipartRequest object will expect HttpRequest object) which i'm having little knowledge about how to do but i guess u can play w/ RequestWrapper or something...
i know MultipartRequest object internally use RequestWrapper but i've never used it so i fear i cant guide further..
regards
maulin
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the MultipartRequest API:
To avoid collisions and have fine control over file placement, there's a constructor variety that takes a pluggable FileRenamePolicy implementation. A particular policy can choose to rename or change the location of the file before it's written

So that sounds like you can implement FileRenamePolicy with your own class, and this is where I'd implement your file renaming logic.

Another option, is to extend the DefaultFileRenamePolicy. You could do step #2 and #3 as described in your logic, and then submit *that* name to the DefaultFileRenamePolicy (accomplishing #4) class (through a call to super()). This class will do #5 for you.

Re-use is cool
[ August 17, 2003: Message edited by: Mike Curwen ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic