-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I can do upload file and save the file. The problem is file saved on wrong place.
I'm using Tomcat, currently uploaded file saved to D:\apps\webserver\Tomcat
This is wrong, the uploaded file should be saved on D:\apps\webserver\Tomcat\webapps\myweb\upload or web perspective on http//localhost/myweb/upload
i hope there's no suggestion to add 'webapps/myweb/upload'...
my code :
public class Upload { public static void saveToDisk() throws Exception { org.zkoss.util.media.Media media = Fileupload.get(); File f=new File(media.getName()); InputStream inputStream= media.getStreamData(); OutputStream out=new FileOutputStream(f); byte buf[]=new byte[1024]; int len; while((len=inputStream.read(buf))>0) out.write(buf,0,len); out.close(); inputStream.close(); String filepath = f.getAbsolutePath(); mdbConverter mdb = new mdbConverter(); Messagebox.show(filepath); } }
Thanks for help...
Play with this:
// Get the real path for the report
String repSrc = Sessions.getCurrent().getWebApp().getRealPath("/WEB-INF/reports/order/Test_Report.jasper");
Hmmm, do you think it's a good idea to store files in the tomcat/webapps folder? What is by a clear and new deploy?
you can save the stream of bytes that represent your file in a blob o clob field in your database (say oracle).
for example check http://www.roseindia.net/jdbc/save_image.shtml
hi xadim......
try out this
org.zkoss.util.media.Media media = Fileupload.get();
File aud = new File(media.getName());
String filepath = aud.getAbsolutePath();
alert(""+filepath);
PreparedStatement stmt = con.prepareStatement("INSERT INTO table values(?, ?)");
stmt.setString(1, n1.value);
stmt.setString(2, filepath);
you have to create a table using datatype blob for image or audio file..... i hope u know that
hi rotkad
Not yet
I can only save the path in database
<image id="mainImage" />
<hbox>
Image name:
<textbox id="imgText" cols="20" />
</hbox>
<hbox>
<button label="Display"
onClick="displayImage(imgText.value)" />
<button label="Add">
<attribute name="onClick">
{
Object media = Fileupload.get();
if (media instanceof org.zkoss.image.Image)
{
mainImage.setContent(media);
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test";
ResultSet rs = null;
PreparedStatement psmnt = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root",
"ddstssm");
File fichier = new File(media.getName());
String filepath = fichier.getAbsolutePath();
alert("" + filepath);
imgText.setValue(filepath);
File image = new File(filepath);
psmnt = connection
.prepareStatement("insert into photo(nom, path) "
+ "values(?,?)");
psmnt.setString(1, "Test Photo");
psmnt.setString(2, filepath);
int s = psmnt.executeUpdate();
if (s > 0) {
System.out.println("Uploaded successfully !");
} else {
System.out.println("unsucessfull to upload image.");
}
} catch (Exception ex) {
System.out.println("Found some error : " + ex);
} finally {
connection.close();
psmnt.close();
}
}
else
alert("Not an image: ");
}
</attribute>
</button>
Please i need help to cotinious
Thanks
Asked: 2010-02-14 20:54:15 +0800
Seen: 2,384 times
Last updated: Jul 13 '15