Keith Alperin - 2005-05-26

Greetings!  I was having a problem with files that i had uploaded via a form where I had set the file thusly:

UploadFileSpec spec = new UploadFileSpec(myFile);
UploadFileSpec[] specs = {spec};
form.setParameter(name, specs);

myFile was on my local machine at /Users/me/myFile.gif and was supposed to be uploaded to the server at /data/uploads/myFile.gif.  Unfortunately, my app was trying to upload it to /data/uploads/Users/me/myFile.gif .  The problem is that when you use the UploadFileSpec(File) constructor, it sets the name of the file to be it's full path (/Users/me/myFile.gif in my case) rather than just the name (myFile.gif).  The solution to this problem is to use an alternate constructor for UploadFileSpec:

UploadFileSpec spec = new UploadFileSpec(myFile);
spec = new UploadFileSpec(myFile.getName(), new FileInputStream(myFile), spec.getContentType());

which explicitly sets the name to "myFile.gif"

Cheers,
Keith R. Alperin