Chandraa.V
|
Posted: 07/25/2005, 4:07 AM |
|
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);
}
%>
Quote :i am using same code.In case of audio file, there are disturbances. Please can you suggest me regarding this problem.
Thanks in advance
|
|
|
chandraa
|
Posted: 07/25/2005, 4:10 AM |
|
Can you please suggest me for the changes to upload audio files without any loss of quality
|
|
|
Rajesh Boddepalli
|
Posted: 07/28/2005, 3:50 AM |
|
Hi Ramesh Kumar Swarnkar,
Thanks much. I am using your code for solving the UNC path issue in diffent way. Once again thanks much. but i am not able to upload bigger file.
Cheers,
RajeshB
|
|
|
DrDeath
|
Posted: 08/03/2005, 12:23 PM |
|
Here is a fix given earlier in the forum by Tom for fixing this error
:
Error Occured.java.lang.IndexOutOfBoundsException: The supplied offset + length did not fit into the supplied byte[] (offset + length = 8192 + 77535 = 85727 vs byte[].length = 77535)
:
change this line:
byteRead = in.read( dataBytes, totalBytesRead, formDataLength );
change to this:
byteRead = in.read( dataBytes, totalBytesRead, formDataLength - totalBytesRead );
|
|
|
bennyz12
Posts: 1
|
Posted: 08/04/2005, 1:00 AM |
|
Is there any solution for the upload image withou using the <input type="file"> ?
the browser that i deal with cannot support file type
|
|
|
siva
|
Posted: 08/07/2005, 1:01 AM |
|
hello Raheel Rehman ,
I have one Problem. i am using your code. i want to find the seleted file size. if i selected more than on 1MB i need to display message & redirect the same thing.
Can you pls help me on this urgently.
Thanks & regards
Siva
sadasiva@gmail.com
|
|
|
CG
|
Posted: 08/14/2005, 7:50 AM |
|
Thanks for making it simple!
Quote Raheel Rehman:
Hello Guys,
I have tried this example and successfully load the file on the server.
-----------------Form.html-------------------------------------------
<form action="upload.jsp" method="POST" enctype="multipart/form-data">
<!-- enctype="multipart/form-data" -->
<input type="file" name="theFile"><br>
<input type="submit">
</form>
------------------------------ upload.jsp --------------------------------------------
<!-- 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);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print("FileName:" + saveFile.toString());
//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;
saveFile = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\ROOT\\Extrusions\\" + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);
//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
%>
As you can see the path in Extrusions this is the path where I can save the files.
It will work, I am sure please try as it is.
Raheel Rehman
|
|
|
mehdi
|
Posted: 08/16/2005, 8:55 AM |
|
I Try upload image into oracle but i couldnot,please help me,
|
|
|
krishna
|
Posted: 08/18/2005, 7:07 PM |
|
Any source code uploading the directory and sub directories and its files
With Regards,
Krishna
|
|
|
Eddie
|
Posted: 08/25/2005, 7:50 AM |
|
I am getting this error when I run this in jdeveloper 10g.
Any suggestions???
java.lang.IndexOutOfBoundsException: The supplied offset + length did not fit into the supplied byte[] (offset + length = 8192 + 19907 = 28099 vs byte[].length = 19907) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.EvermindServletInputStream.read(EvermindServletInputStream.java:119) at java.io.DataInputStream.read(DataInputStream.java:224) at _uploadform._jspService(uploadform.jsp:22) [/uploadform.jsp] at com.orionserver[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].http.OrionHttpJspPage.service(OrionHttpJspPage.java:57) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:347) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65) at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192) at java.lang.Thread.run(Thread.java:534)
I am using this form:
<form method="post" ACTION="uploadform.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>
I am using this code:
<%
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);
}
%>
|
|
|
amar nath gupta
|
Posted: 08/28/2005, 9:12 AM |
|
hi all , i am amar ,
i have one question , " how to upload the image in the JSP "
Plz Help me , i want to code of the that question ,
If Any know Then Plzz Send Me ,
Thanking you
Amar
|
|
|
Stan
|
Posted: 08/29/2005, 3:50 AM |
|
Hi,
I am trying to display a blob image from MySql database into a jsp page (that having text fields also) without using any additional jsp and servlet. But I can't.
Please help me if any one knows...
Thanks in advance.
Stan.
|
|
|
sini
|
Posted: 08/29/2005, 11:42 PM |
|
I have a picture in my database,
and i want to display it on a jsp using struts.
how can i proceed ??
I have an image in my database.
How can i randomly viewing image on jsp from the database
|
|
|
kamal
|
Posted: 09/05/2005, 3:33 AM |
|
can any body tell me abt how to upload file using FTP. if possible give the java code.
|
|
|
Vinu
|
Posted: 09/05/2005, 10:12 PM |
|
Hi Vinu,
I had sent you a mail and still have not got a reply to it. this is regarding a problem i am facing. i have to download a doc file to my desktop from any part of the world, modify it and upload it to the source server. kindly alk to your friends about it and mail me.
This is
with regards
Sudhir Venugopal
|
|
|
sabi
|
Posted: 09/07/2005, 2:36 AM |
|
hi guys,
i wanna know how a jsp page can be connected using jdbc
think u may reply
|
|
|
Alvaro Cobo
|
Posted: 09/08/2005, 3:20 PM |
|
Hi Vinu:
If I am not wrong you are looking for a whole application to manage
documents.
I would recomend you to check packages like MyDMS, which you can find
googling it. This is a php/mysql application and could be the solution you
are looking for.
Best regards,
Alvaro.
"Vinu" <Vinu@forum.codecharge> escribió en el mensaje
news:9431d25383465c@news.codecharge.com...
> Hi Vinu,
>
> I had sent you a mail and still have not got a reply to it. this is
regarding a
> problem i am facing. i have to download a doc file to my desktop from any
part
> of the world, modify it and upload it to the source server. kindly alk to
your
> friends about it and mail me.
>
> This is
>
> with regards
> Sudhir Venugopal
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
hkus
|
Posted: 09/16/2005, 12:33 AM |
|
well thank u for all programmer in the world
thank u!
danke
mercy
|
|
|
vamsi
|
Posted: 09/21/2005, 11:15 PM |
|
Quote Minn:
go for blob type objetcs
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
|
|
|
song
|
Posted: 09/23/2005, 4:20 PM |
|
about the above code, even though i change
byteRead = in.read( dataBytes, totalBytesRead, formDataLength );
to
byteRead = in.read( dataBytes, totalBytesRead, formDataLength - totalBytesRead );
there is still problem ( IndexOutOfBoundsException).
And, this prolbem only heppens when i tried to upload binary file.
And, my webserver is linux+tomcat.
thanks.
|
|
|
Amitchavan
|
Posted: 09/26/2005, 4:30 AM |
|
hi there
i go throug that gode but i am not able to find the file whic the program uplods
can able to tell me where this program saves the file on server
thank
|
|
|
peterr
Posts: 5971
|
Posted: 09/27/2005, 10:17 AM |
|
You can use the "FileUpload" component in CodeCharge Studio to create Java Servlet or JSP page with upload functionality. This will automatically generate the JSP or Java program that allows users to upload their files to your server.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
|