Unique Id creation
Hi All, I am using struts2 in my web application. Which is the best way to create unique Id for each file upload i do in my application...? Thanks Ala
Re: Unique Id creation
jayakumar ala wrote: Hi All, I am using struts2 in my web application. Which is the best way to create unique Id for each file upload i do in my application...? Thanks Ala I've always used the original filename with a time stamp, down to the millisecond formatted with leading zeros and without separators, appended to the end. If a create fails, I wait a few milliseconds and regenerate the filename. The nice part about the time stamp is that you have the date and time the file was uploaded in the name itself. TG - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Unique Id creation
I use File.createTempFile: http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File) Then I relate the uploaded filename with the saved temp file name in a database table. Gabriel 2009/12/15 Todd Grigsby : > jayakumar ala wrote: >> >> Hi All, >> I am using struts2 in my web application. >> Which is the best way to create unique Id for each file upload i do in my >> application...? >> >> Thanks >> Ala >> >> > > I've always used the original filename with a time stamp, down to the > millisecond formatted with leading zeros and without separators, appended to > the end. If a create fails, I wait a few milliseconds and regenerate the > filename. The nice part about the time stamp is that you have the date and > time the file was uploaded in the name itself. > > TG > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Unique Id creation
I am trying to upload multiple files in my application , So i am looking for different approach to create unique Id for all the uploaded files. Any suggestions are appreciated. On Tue, Dec 15, 2009 at 1:54 PM, Gabriel Belingueres wrote: > I use File.createTempFile: > > > http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File) > > Then I relate the uploaded filename with the saved temp file name in a > database table. > > Gabriel > > 2009/12/15 Todd Grigsby : > > jayakumar ala wrote: > >> > >> Hi All, > >> I am using struts2 in my web application. > >> Which is the best way to create unique Id for each file upload i do in > my > >> application...? > >> > >> Thanks > >> Ala > >> > >> > > > > I've always used the original filename with a time stamp, down to the > > millisecond formatted with leading zeros and without separators, appended > to > > the end. If a create fails, I wait a few milliseconds and regenerate the > > filename. The nice part about the time stamp is that you have the date > and > > time the file was uploaded in the name itself. > > > > TG > > > > - > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: Unique Id creation
java.util.UUID.randomUUID() ? http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.htm PK jayakumar ala wrote: I am trying to upload multiple files in my application , So i am looking for different approach to create unique Id for all the uploaded files. Any suggestions are appreciated. On Tue, Dec 15, 2009 at 1:54 PM, Gabriel Belingueres wrote: I use File.createTempFile: http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createTempFile(java.lang.String,%20java.lang.String,%20java.io.File) Then I relate the uploaded filename with the saved temp file name in a database table. Gabriel 2009/12/15 Todd Grigsby : > jayakumar ala wrote: Hi All, I am using struts2 in my web application. Which is the best way to create unique Id for each file upload i do in my application...? Thanks Ala I've always used the original filename with a time stamp, down to the millisecond formatted with leading zeros and without separators, appended to the end. If a create fails, I wait a few milliseconds and regenerate the filename. The nice part about the time stamp is that you have the date and time the file was uploaded in the name itself. TG - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Unique Id creation
OP: What Struts tag are you using to upload multiple files at the same time? I may be wrong, but I didn't know this was possible with Struts. If so, what filename are they given by default? I use file upload tags but they are saved as default-named files I can access via the File setter in my Action (file.getAbsolutePath()). Otherwise, I would suggest going with a solution along the line of PK's solution with UUID (probably best with the ms timestamp) as part of the file name or using SecureRandom.nextInt and Integer.MAX_VALUE. To be extra safe, you could have a static Set to maintain all file names and ensure it not is contained in that Set before creating it (and populate the Set during initialization). TG, Out of curiosity, why would the current milliseconds past epoch need to be zero-padded? (besides code written for ~277 years from now, when it still likely wouldn't matter?) -Original Message- From: Todd Grigsby [mailto:strutsu...@tgrigsby.com] Sent: Tuesday, December 15, 2009 3:02 PM To: Struts Users Mailing List Subject: Re: Unique Id creation jayakumar ala wrote: > Hi All, > I am using struts2 in my web application. > Which is the best way to create unique Id for each file upload i do in my > application...? > > Thanks > Ala > > I've always used the original filename with a time stamp, down to the millisecond formatted with leading zeros and without separators, appended to the end. If a create fails, I wait a few milliseconds and regenerate the filename. The nice part about the time stamp is that you have the date and time the file was uploaded in the name itself. TG - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Unique Id creation
I am using Jquery MultiFile to select multiple file. I still be selecting one by one file but when i do upload it will be multiple file. There are other ways to select multiple files through Browse button like Flash components or Applet. On Tue, Dec 15, 2009 at 9:39 PM, Lee Clemens wrote: > OP: What Struts tag are you using to upload multiple files at the same > time? > I may be wrong, but I didn't know this was possible with Struts. If so, > what filename are they given by default? I use file upload tags but they > are > saved as default-named files I can access via the File setter in my Action > (file.getAbsolutePath()). > > Otherwise, I would suggest going with a solution along the line of PK's > solution with UUID (probably best with the ms timestamp) as part of the > file > name or using SecureRandom.nextInt and Integer.MAX_VALUE. > > To be extra safe, you could have a static Set to maintain all file names > and > ensure it not is contained in that Set before creating it (and populate the > Set during initialization). > > > TG, Out of curiosity, why would the current milliseconds past epoch need to > be zero-padded? (besides code written for ~277 years from now, when it > still > likely wouldn't matter?) > > -Original Message- > From: Todd Grigsby [mailto:strutsu...@tgrigsby.com] > Sent: Tuesday, December 15, 2009 3:02 PM > To: Struts Users Mailing List > Subject: Re: Unique Id creation > > jayakumar ala wrote: > > Hi All, > > I am using struts2 in my web application. > > Which is the best way to create unique Id for each file upload i do in > my > > application...? > > > > Thanks > > Ala > > > > > > I've always used the original filename with a time stamp, down to the > millisecond formatted with leading zeros and without separators, > appended to the end. If a create fails, I wait a few milliseconds and > regenerate the filename. The nice part about the time stamp is that you > have the date and time the file was uploaded in the name itself. > > TG > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >