aspose file tools*
The moose likes Servlets and the fly likes File Upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "File Upload" Watch "File Upload" New topic
Author

File Upload

ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi,

I am using com.oreilly.servlet.MultipartRequest for uploading files in servlets. But when my application is moved to a weblogic server...file upload doesnt work, it gives a error: "Not a directory" in weblogic, but works just fine in servlets. Do I need to change something for it to work while on weblogic server ?

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you setting the location on the drive for the uploaded files?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi Ben,

The path is ../folder1/folder2. Folder2 being the folder to which the files get uploaded.

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

So your locating the folder by looking in folders relative to the current working directory from where the JVM was invoked?
Is this directory inside the webapp?
Can you post the code that locates the directory?
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi Ben,

Thanks for the immediate reply. This directory is in my web app.

Heres the code in servlets:
MultipartRequest multi =
new MultipartRequest(request, "../folder1/folder2", 10 * 1024 * 1024,
new com.oreilly.servlet.multipart.
DefaultFileRenamePolicy());

This works perfectly in servlets. But when I move it to the weblogic server...its not working. The path on the weblogic server where the program is running with an error "Not a directory" is: http://folderone/foldertwo/folderthree/folder1/folderfive/folder6 wherein folder6 is the java program name and folder1 corresponds to the foldername (folder1) listed in my java program.

I hope it helps.

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Try using an absolute path for the directory.
While your at it, make it a directory that isn't inside the web app -- at least initially.

Finding files on the local system with relative paths is always risky.
You're counting on the current working directory of the JVM always being the same.

Also, if your app server is configured to run the app as a packed war file (without unpacking to an exploded file system), you will not be able to write to directories within the app.

Your best bet is to always use an absolute path that is configured as a servlet or context init param, with the directory being outside of the webapp. Write a servlet that streams the files if you need to access them again for downloading.

Try with an absolute path and let us know if it helps.

-Ben
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi Ben,

Thanks a lot for the detailed explanation. I will try to use an absolute path.

Thanks.
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi,

When I am using an absolute path on the weblogic server, I am getting this error: "Error 500--Internal Server Error
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
The server encountered an unexpected condition which prevented it from fulfilling the request". What does this mean...does it have to do anything with weblogic configuration or got to do with my java file upload application. The same program works just fine on my Java server.

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Is your absolute path pointing to a directory within your webapp?
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi Ben,

Thanks for the response. Yes, the absolute path is pointing to a directory in my web application. Please let me know where I am going wrong.

Thanks for all the help.
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi,

I would like to know if Multipart Request file upload is not compatible on weblogic servers. My upload application works fine on Java platform but not when migrated to weblogic server. Any suggesstions ?

Thanks,
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ford Darcy Jr:
Hi Ben,

Thanks for the response. Yes, the absolute path is pointing to a directory in my web application. Please let me know where I am going wrong.

Thanks for all the help.


Is your web application running as a packed war file or as an exploded file system?
ford Darcy Jr
Ranch Hand

Joined: Jan 26, 2005
Posts: 76
Hi,

Now my code works fine even on Weblogic. I just had to set the path right.

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Glad it's working,
Thanks for posting back the results.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Upload