I am trying to develop a File Upload facility for my website.Because of restrictions from my hosting services I am not able to "write" anything on the server. So I am trying to insert the file into database.For that I need to read the file and then insert it into database.
All this works fine on my local machine.But on my hosting service,it doesn't. I get a exception which is..
In a web application, "uploading a file" does not involve reading any files. It simply involves reading a stream of data from the request. So read from that stream and copy the data directly into the database. I use Apache Commons FileUpload to do this.
Joined: Dec 03, 2001
Thanks for the immediate response. I was waiting well,by reading the file,I didn't mean it.I am giving my code.
Even the uploadFile.length() throws java.security.AccessControlException: access denied
do let me know if I need to change anything, also can you give some code hints plz thanks -Vrunda
Although, a better way to do it is use the apache commons fileupload. You may want to alter your code a bit in order to achieve file upload facility. As far as i can think, the problem wont arise in reading the byte stream from the request or writing it to the db, instead, when you are accessing the file, this is when you will encounter this issue.
So Vrunda, could you please tell us how would you access the client's file?
Joined: Dec 03, 2001
Hi Murad Iqbal,
Thanks for your reply.I really appreciate it.You can see the code which I have written in my earlier post. That is how I am reading a file from client side.From a jsp page which has a "input type=file" I am submitting it to a servlet,and then through that servlet,I am calling a .java prog which is doing the actual file upload to database.
Also,to use apache commons fileupload,what do I need to do?
Thanks a lot, -Vrunda Joshi
Joined: Dec 03, 2001
Since I am not able to solve my problem,I am thinking of implementation authentication.Which I think might implement security and will help to read and write to/from client and to the database.
Does this sound a good solution? Which type of authentication would be suitable? I am new to this.
I'm really not understanding what's going on. If the file is being uploaded from the client, then why is the database code using FileInputStream to read it? This class would be used to read a disk file on the server -- but you don't have a disk file on the server, you have a stream of bytes from the client. As has already been stated, there should be no reason whatsoever to open any disk files on the server.
Sometimes people new to web app development (and even people not so new) get confused about what happens on the server, and what on the client, and whether a file path refers to a path on the client or on the server -- perhaps this is one of those times?
java.security.AccessControlException: access denied java.io.FilePermission C:\Documents and Settings\Mandar\My Documents\Vrunda\abc.txt read)
I am coming late to this discussion so I may have missed something but that looks like an exception thrown on your client program that has nothing to do with the service. That looks like a windows path and I doubt that godaddy hosting runs on Windows. Bill
I second Ernest - I don't understand what's going on. When uploading a file to a web server, you do not have a file. Why do you even use FileInputStream - there's no possible way it could do something useful. Where is this code you posted supposed to run?
Thanks for your replies. Looks like I have created a lot of confusion here. Let me explain.
I am working on website which is hosted by (has hosting service)godaddy.We are having Linux based hosting plan.
I am developing a File upload component,so that anybody will be able to uplad file on the site from anywhere when he/she visits the site,I want to insert the file into the database that's with the godaddy's site.For that purpose,I was using FileInputStream,I don't know anyother better/simple way.Please let me know.
I have developed this program on my own and I have been testing it on my local pc,local db which was working fine. I put it on godaddy to test it,and it has stopped working and it's giving me the exception I have mentioned. So I am really not able to understand what the problem is?One reason I think is,it's restricting the WEB-INF/classes folder from reading client files.
Again that's what I think, Please bear with the lengthy explaination, I hope I've made myself clear now. I do apologize for the inconvinience that has caused and I really appreciate your replies. Thanks -Vrunda Sorr
Joined: Mar 22, 2005
You do not need a client-side file upload component - the browser and a simple HTML page will suffice. For the server-side file upload component, look into Jakarta Commons FileUpload. More than likely it does everything you need done. You will end up with the file contents in a byte array. That you can store in a database, probably as a Blob type. Nowhere is there any File or File[In|Out]putStream involved in any code you need to write. As you have discovered, you are not allowed to use that anyway.