Aleks Kushch

+ Follow
since Oct 31, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aleks Kushch

I managed to get around the problem. I had to set write permissions as 777 to temp folder in /home/donnarosa/tmp.

and also change factory.setRepository(new File("/tmp")); to factory.setRepository(new File("/home/donnarosa/tmp"));

It still doesnt work, the directories are written to the database, but the actual image file is not saving into /home/donnarosa/web-root/Uploaded_Images.

Any ideas?

I'm moving this to a more appropriate forum, as it's not really JSP-related.

Can you give a link to where you moving this.

Why not make the temporary directory something you can write to? I dont know what you mean. If I create a tmp dir anywhere in root of my accounbt it seesm to need write permissions

What is IIRC?

I think I am slowly beging to understand what is wrong.

According to apache commons:

What happens during the file upload is that the files are first stored temporarily on disk on the server. "Is this right?"

And the repository into which they are stored temporarily into, is set to system default temp directory.

In my case, the default repository will be "/home/tomcat/default/temp/upload_18249544_124a245f512__7ff4_00000062.tmp".
Thats why I get Access Denied error becasue it is a security risk to write to this folder and the hosting company blocks writing to this folder.

So David Newton was right at suggesting that commons-fileupload saves the files first to temp directory and then to the directory that you specify. I didn't realise that was the case.

So to solve the problem, we need to change the default repository dir from default to root location on the server:

First create tmp folder in you root dir.

Second change the repsitory using the following code:

DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File("/tmp"));

Now the file will be attempted to be writen to new temp dir.

I still get an error and cannot write to /tmp because there are now write permissions set for this folder, so I contacted hosting support to enable write permissions.

I post an update on mu progress soon..

David Newton wrote:I'd guess it's commons-fileupload that's saving to the temp directory first.

How can i change that? I looked at that link, but the infomration thre is limited, to torubleshoot this problem.
I have hit rock bottom with this, please help

I am trying to upload images onto a shared hosting server (Tomcat 6), using multipart/form-data POST request and org.apache.commons.fileupload API.

After the program extract the images from the multipart/form-data, it writes them to disk using the following code:

config.getServletContext().getRealPath("/"+"Uploaded_Images") returns the follwoing path to which the file should be written to "/home/donnarosa/web-root/Uploaded_Images".
However tomcat throws the following error:

Why the hell is Tomcat 6 trying to write the file to /home/tomcat/default/temp/upload_18249544_124a245f512__7ff4_00000062.tmp, this is tomcat default temporary directory. I specifically tell it to write to "/home/donnarosa/web-root/Uploaded_Images". It is like it completely ignores the path that i specify.

I asked hosting support about this and that what they replied:

Looking at this line: access denied ( /home/tomcat/default/temp/upload_18249544_124a245f512__7ff4_00000020.tmp write)

it seems to me that you're trying to use the tomcat default temporary directory.
Your application is not allowed to write there as this is a security risk. You should use a directory which is under your home directory. E.g. create /home/donnarosa/tmp and do a
chmod a+w tmp

Any suggestions or help will deeply appriciated.