PDA

View Full Version : [HELP] How to create image & file upload in jsp?



bulongx
16 Dec 2010, 12:24 AM
Hi everyone, pls help me to create image & file upload in jsp...

and what data type to save image & file uploaded in PostgreSQL database?

Hopely u all can help me! Thanks b4... :)

bulongx
16 Dec 2010, 6:16 AM
Plzzz... fix my code below...

My JSP Code :


{
xtype: 'fileuploadfield',
id: 'file',
emptyText: 'Select an image',
fieldLabel: 'Foto',
name: 'photo-path',
anchor:'35%',
disabled: true
}
My getting value code in my jsp :


Ext.getCmp('file').getValue()
n' in java file. how to get the value for file uploaded? where i placed stored folder?? how i set it? or u have more simply than my code? pls share to me...

thanks for see my problem... n' more thanks if u can help me to fix my problem...

Animal
16 Dec 2010, 6:57 AM
On the client, you cannot get the value of a file input.

You can get the content of a file if you use the HTML5 File API.

On the server side, this is a JEE question. There are classes available to process file uploads. They are not normal parameters.

http://www.google.co.uk/search?hl=en&q=J2EE+file+upload&aq=f&aqi=g1g-v2&aql=&oq=&gs_rfai=

kingk
16 Dec 2010, 7:02 AM
Hi!
I would suggest to take the JS code of one of the examples in the link below:
http://dev.sencha.com/deploy/dev/examples/form/file-upload.html

replace the url in the file-upload.js

url: 'file-upload.php',with your jsp page
and add something like the following to your upload.jsp file:

Actually this is Java Code:


List fileItemsList = servletFileUpload.parseRequest(request);
Iterator it = fileItemsList.iterator();
while (it.hasNext()) {
FileItem fileItemTemp = (FileItem) it.next();
File file = File.createTempFile("upload_", fileItemTemp.getName().substring(fileItemTemp.getName().lastIndexOf('.'), fileItemTemp.getName().length()), finDir);
fileItemTemp.write(file);

out.println("{success:true, file:'" + file.getName() + "'}");
}
After adding some imports, the thing should work!