Hi Sergey, I'm not sure that it would be possible to make it any more configurable, as I think the name will always need to have some element of randomness to it, to avoid clashes if the same file is uploaded concurrently, or multiple times.
However, if it was possible to access the name of the temp file that has been created, I think that, for now, that would be enough, at least for what we are trying to do. I notice that when the file is written to disk, the InputStream is actually a CachedOutputStream, and this does have the path to the file, however, it is not possible to cast the CachedOutputStream to an input stream and access the name. I guess there is some inner class that wraps the OutputStream somewhere but if it was possible to abstract that somehow, that would be good. Another, but no doubt more complicated, solution might be to do something similar to Spring. They have a class called MultipartFile, which has a method called transferTo. This uses commons-fileupload to move the file using different techniques depending on where the file is. If the file has been written to disk it will try to call renameTo on a File, and if that fails it will copy it using Input/OutputStream streams. If the file is in memory it will again use Input/OutputStream to do the copy. If you look at the source of DiskFileItem.write() then you will get a better idea of what I mean. That was there is a common way of moving a file from an attachment, where ever it resides. Thanks for the help so far! Graham On 7 January 2014 11:57, Sergey Beryozkin <[email protected]> wrote: > Hi > It may make sense indeed to simplify an access to the underlying temp file > or perhaps make the naming more configurable, > I'm not sure yet how this can be done but hope we can come up with some > solution > Thanks, Sergey > > > On Mon, Jan 6, 2014 at 12:35 PM, Graham Ford <[email protected]> > wrote: > > > Hi, > > > > We are having an issue with attachments to a REST call we are making. We > > have set up the attachment-directory property so that the file is written > > to a set directory, but we then need to move it to somewhere else. We can > > do this by accessing the InputStream from the attachment and then using > an > > OutputStream to write the file, but this is not very performant from us. > > The temporary directory is located on a network drive, and we want to > move > > it to another directory on this drive, meaning a simple file move/rename > > would be the ideal way to do this. > > > > The problem is that the temporary file it written with a random name, and > > so although we know which directory is resides in, we don't know which > file > > in that directory is the one from the current call. So, is there either a > > way of getting the name of the temporary file that has been written, or > is > > there another way that we would be able to accomplish what we want to do? > > > > Hope this is clear, and please feel free to ask if anything doesn't make > > sense! > > > > Thanks > > Graham > > > > > > -- > Sergey Beryozkin > > http://sberyozkin.blogspot.com > Talend - http://www.talend.com > -- Graham Ford Software Developer Kulu Valley Ltd. 91 Goswell Road London EC1V 7EX Direct: +44 207 017 8326 Tel: +44 207 253 8080 Fax: +44 207 017 8338 Web: www.kuluvalley.com Privacy and Confidentiality The Information contained in this e-mail and any attached files are intended for the named recipient(s) only. It may contain legal, privileged and/or confidential information and if you are not an intended recipient, you should not copy, distribute or take any action in reliance on it or disclose its contents. If you have received this e-mail in error, please notify the sender immediately and then delete it. Internet e-mail is not a secure medium. Any reply to this message could be intercepted and read by someone else. Please bear that in mind when deciding whether to send material in response.
