aspose file tools*
The moose likes Servlets and the fly likes Help needed with MultipartRequest from O'Reilly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help needed with MultipartRequest from O Watch "Help needed with MultipartRequest from O New topic
Author

Help needed with MultipartRequest from O'Reilly.

Jacek Nabywaniec
Greenhorn

Joined: Aug 16, 2003
Posts: 4
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?
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
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
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed with MultipartRequest from O'Reilly.
 
Similar Threads
NX: URLyBird 1.2.1 - Character encoding
UploadedFile and filenames with non-ascii chars
passing control from applet to servlet
uploading multiple files, 'post' not working off server (works fine off local host)
How to change the File name before uploading it.