Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing filenames in a Multipart request ?

Status
Not open for further replies.

scotth4v

Programmer
Apr 17, 2001
103
US
Hi Guys,

Following your wonderful advice, I've incorporated O'Reilly's multipart request classes to add file upload fuctionality to my bugtracker project. It works beautifully, however, I found a slight bug and was wondering if any of you have come across it, and if so, what are some possible solutions.

The bug: If you upload a file with the same name, it overwrites it. (IE: If someone attaches "error.log", it will replace the old one.)

One thing I considered is to append a unique parameter from the request to the filename (IE append the bug # to the filename, so you'd have "1234error.log" etc.) This would require modifying his classes and creating a new jar file (which I've never done, I'm a newbie... :) how hard is that? Is that doable within his liscence agreement?

I guess I'm asking what is the best way to rename a file before it gets copied. Is what I've described the best way to do it, if not, what would you recommend?


Thanks a bunch,

-Scott

(Sorry if this is a simple, boneheaded, question. I'm not a Java Developer and I'm teaching myself how to do this stuff and don't have anyone here to bounce ideas off of ;)
 
I figured it out...

after the file was uploaded, I renamed it, not before... really simple, as I surmised it would be. Like I said, I'm learning. ;)

Here's the code snippet for the archives...

Code:
File f = multi.getFile(name);  
File newfile = new File(issueID+ "_" + filename);   
if (f != null) {          
   f.renameTo(newfile);
   //other statements, etc...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top