Roger
|
Posted: 03/08/2004, 5:12 AM |
|
Hi,
Are there any java/JSP examples of the file upload?
R.
|
|
|
innovated
Posts: 1
|
Posted: 03/14/2004, 3:21 PM |
|
I would like to know too, anyone know please suggest
|
|
|
cfell
Posts: 10
|
Posted: 03/14/2004, 10:25 PM |
|
I've used the CCS file upload form... are you having a specific problem? I'm using it to upload files for batch processing purposes. The form inserts a record into my database that contains the uploaded file name and a backend Java process wakes up at scheduled times to query the database for new files to process. I can provide more detail or you can have a look at the examples in CCS help.
Regards,
Curtis
|
|
|
Roger
|
Posted: 03/22/2004, 6:36 AM |
|
Curtis,
I've tried to get the basics working. Is there a quick howto or have you a sample I could look at.
Basically I'd like to upload an emp image into a database field using java/jsp.
Direction would be greatly appreciated
Regards
R.
|
|
|
Ishtiyak
|
Posted: 04/26/2004, 5:10 AM |
|
Hai!!
I have some code samples searched from net, but few are using FTP, few I am not getting. I am not able to find the complete solution. Do send me if you find somewhere.
|
|
|
Kate
|
Posted: 05/18/2004, 11:02 AM |
|
Hi
I am trying to upload file from cleint machine to the database in the server side using Java.I have to give it a name and ID before saving it to the database. I am also using Tomcat.I am a novice in this field.
Any suggestion,direction or sample would be a great help and would be greatly appreciated.
Thanks
Kate
|
|
|
Minn
|
Posted: 05/18/2004, 12:16 PM |
|
Hi,
I am making web page with jsp in websphere server. I would like to upload image file to my MSACCESS database and I dont know how to do. I am new to java. But I am learning quite first and I can insert some fileds to the database.
Can you please send me the code.
Thanks
|
|
|
Manish Mehta
|
Posted: 06/04/2004, 10:07 AM |
|
You would not want to upload a image into the database.
What if the image is large ?
Also retrieving the image would be a problem too.
|
|
|
ducvuong
|
Posted: 06/17/2004, 12:11 AM |
|
Hi all.
I'm going to write a JSP page, My problem is how can I create a page that have rows, each row contain user account, name, .... and one button, which when i click on, it will link to another page then i can delete or update this account?. Please help me.
|
|
|
Rakesh
|
Posted: 06/19/2004, 5:29 AM |
|
Please go to the site
http://www.oop-reserch.com/mime_example_5.html
|
|
|
swarna
|
Posted: 06/29/2004, 11:08 PM |
|
Quote Roger:
Hi,
Are there any java/JSP examples of the file upload?
R.
|
|
|
Vijay
|
Posted: 07/08/2004, 9:08 PM |
|
www.javazoom.net/jzservlets/uploadbean/uploadbean.html
try the above link, damn good... but it cant be used for comercial use, so customize it according to ur need!!
Cheers
Vijay
|
|
|
Ramesh Kumar Swarnkar
|
Posted: 08/01/2004, 11:33 PM |
|
Well Friend, I worked on this code successfull ; I hope it will solve your problem too :)
<!-- upload.jsp -->
<%@ page import="java.io.*" %>
<%
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print(dataBytes);
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
FileOutputStream fileOut = new FileOutputStream(saveFile);
//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
%>
|
|
|
Ails
|
Posted: 08/04/2004, 8:43 PM |
|
To Mr. Ramesh Kumar Swarnkar
I was surfing and looking for options and I chanced on this forum page
Thank you for your code on file uploads It was most helpful and illuminating at best.
Kind Regards,
Ails
|
|
|
ling
|
Posted: 08/08/2004, 8:48 PM |
|
I faced some problem here when upload an image (gif or jpeg) that more than few hundreds KB. the image that I uploaded different with the original image, it seems like distorted.
so is there any solution for it?
|
|
|
hj
|
Posted: 08/10/2004, 12:34 AM |
|
i have the same problems like ling! (with images and *.pdf)
|
|
|
luana_arch
|
Posted: 08/11/2004, 7:41 AM |
|
How can i transfer images from the applet to my server, I've tried using the stream but isn't working, i'll really appreciatte any help.
Thanks
Quote Ramesh Kumar Swarnkar:
Well Friend, I worked on this code successfull ; I hope it will solve your problem too :)
<!-- upload.jsp -->
<%@ page import="java.io.*" %>
<%
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print(dataBytes);
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
FileOutputStream fileOut = new FileOutputStream(saveFile);
//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
%>
|
|
|
SHP
Posts: 4
|
Posted: 08/11/2004, 4:46 PM |
|
Which is the example in codecharge/CSS for usage of FIle Upload (java/jsp)?
I was able to save the filename in the db column using the FIle Upload control in a record form. But when I edit the record, I see the file name as static text with the delete check box besides it. Is there a way i can access the file (probably open it for reading or download it to local space) instead of just seeing the name ? Or am i using it wrong?
Can anyone help with how of if I can use CSS File Upload for doing the above task?
|
|
|
Thuanvd
|
Posted: 08/16/2004, 2:25 AM |
|
I want to have a code for upload image with jsp/servlet
|
|
|
ling
|
Posted: 08/20/2004, 12:58 AM |
|
I just found this example, but haven't test it out yet...
http://www.oop-reserch.com/mime_example_5.html
Try on it, may be it can help you!
|
|
|
jack9190
|
Posted: 08/23/2004, 11:34 PM |
|
Has anyone tried jakart commons FileUpload? It is free and it works fine.
|
|
|
anil
|
Posted: 08/24/2004, 10:01 PM |
|
Quote Roger:
Hi,
Are there any java/JSP examples of the file upload?
R.
|
|
|
phani
|
Posted: 08/31/2004, 5:05 AM |
|
Quote Thuanvd:
I want to have a code for upload image with jsp/servlet
<%@ page import="java.sql.*,java.io.*,java.util.*,com.oreilly.servlet.MultipartRequest,com.microsoft.jdbc.sqlserver.SQLServerDriver;"%>
<%
/* The Following Code is Used To Insert An Image Into Database
String filename="";
try
{
MultipartRequest multi= new MultipartRequest(request,"d:/phani",5*1024*1024);
Enumeration files=multi.getFileNames();
File f=null;
while(files.hasMoreElements())
{
String name=(String)files.nextElement();
filename=multi.getFilesystemName(name);
String type=multi.getContentType(name);
f=multi.getFile(name);
System.out.println("The File is "+f);
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://172.21.1.11:1740;databasename=pubs","sa","satest");
Statement stmt = con.createStatement();
System.out.println("2 "+f);
InputStream is = new FileInputStream(f);
System.out.println("4 "+is);
byte b[]=new byte[is.available()];
is.read(b);
String sql = "INSERT into photo_test (\"Photo\") values('" + b + "')";
System.out.println("sql is " +sql);
stmt.execute(sql);
stmt.close();
}catch(Exception e)
{
System.out.println(e);
}
out.println("The Image is Added into Database");
|
|
|
mahesh
|
Posted: 08/31/2004, 5:36 AM |
|
Hai to Every one I have a solution to JSP Insert image into Database
<%-- This jsp Page is Uploding The Image into Database using MultipartRequest class
FileSystem concepts and ByteArray.
--%>
<%@ page import="java.sql.*,java.io.*,java.util.*,com.oreilly.servlet.MultipartRequest,com.microsoft.jdbc.sqlserver.SQLServerDriver;"%>
<%
/* The Following Code is Used To Insert An Image Into Database */
String filename="";
try
{
//Download com.oreilly package
MultipartRequest multi= new MultipartRequest(request,".",5*1024*1024);
Enumeration files=multi.getFileNames();
File f=null;
while(files.hasMoreElements())
{
String name=(String)files.nextElement();
filename=multi.getFilesystemName(name);
String type=multi.getContentType(name);
f=multi.getFile(name);
System.out.println("The File is "+f);
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver;databasename="xxx","username","password");
Statement stmt = con.createStatement();
InputStream is = new FileInputStream(f);
byte b[]=new byte[is.available()];
is.read(b);
String sql = "INSERT into photo_test (\"Photo\") values('" + b + "')";
stmt.execute(sql);
stmt.close();
}catch(Exception e)
{
System.out.println(e);
}
out.println("The Image is Added into Database");
This code is perfectly working , I could store an image into database using this program but i am unable to retrieve the page. The image is getting decoded but when i am trying to send the content to a file and open it, it is giving me the name fo the file but the picture is not getting opened. So any one can help me.
Thanks advans
|
|
|
Dilip
|
Posted: 09/08/2004, 12:31 AM |
|
Hi,
Can anyone send me the code for how to upload multiple files after clicking "upload" button on the server ....... I did it for one file..
Dilip
|
|
|
Do Tu
|
Posted: 09/09/2004, 3:39 AM |
|
Dear all !
I have some problems with FileupLoad component of Apache. I want handle multipart/form-data request to upload my files whose were available in local drive but not use tag <input type="file"..> (FTP is other solution but i'm not interesting.)
Thank in advance.
|
|
|
timberman
|
Posted: 09/20/2004, 1:49 PM |
|
Wow! Like a piece of cake.
It works like a horse.
Thanks
|
|
|
timberman
|
Posted: 09/20/2004, 1:51 PM |
|
Quote timberman:
Wow! Like a piece of cake.
It works like a horse.
Thanks to Ramesh Kumar Swarnkar
|
|
|
pimms
Posts: 3
|
Posted: 09/22/2004, 9:09 PM |
|
Hi! I am also looking at loading a file into database. can you guys please assist me with the following questions:
1. What datatype should I have in the database? CLOB or BLOB?
2. How could I use a form post for user to select the file and then use the above code to do the upload?
3. Say if I uploaded a pdf file, any one has example how I could display a pdf icon and when click on it, the acrobat read will be activated?
Thank you.
|
|
|
pimms
Posts: 3
|
Posted: 09/22/2004, 9:11 PM |
|
This is a fileupload.html which I have created:
<form method="post" ACTION="fileupload.jsp" name="upform" ENCTYPE='multipart/form-data'>
<input type="file" name="uploadfile">
<p>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
<input type="hidden" name="action" value="upload">
</form>
|
|
|