0

How to save uploaded file on right place ?

asked 2010-02-14 20:54:15 +0800

zuki gravatar image zuki
79 1 1 6

updated 2010-02-14 20:55:41 +0800

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...

delete flag offensive retag edit

9 Replies

Sort by » oldest newest

answered 2010-02-15 08:53:42 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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?

link publish delete flag offensive edit

answered 2010-03-10 09:02:13 +0800

xadim gravatar image xadim
61 1

Hi,

I'am the first zk user in Sénégal

I want to know how to save uploaded file in a mysql database using ZK

It's very very important help me please

Thanks for help...

link publish delete flag offensive edit

answered 2010-03-10 13:46:31 +0800

YamilBracho gravatar image YamilBracho
1722 2

updated 2010-03-10 13:48:12 +0800

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

link publish delete flag offensive edit

answered 2010-03-11 03:15:58 +0800

nageshprabhug gravatar image nageshprabhug
69 1

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

link publish delete flag offensive edit

answered 2010-03-11 11:23:27 +0800

xadim gravatar image xadim
61 1

Hi nageshprabhug

Thanks for answer i'll try and tell you the result

Thanks

link publish delete flag offensive edit

answered 2010-03-17 08:19:03 +0800

rotkad gravatar image rotkad
18

Hi xadim
did you succeed? please share your code if yes.
I'm trying to upload a pdf file.

link publish delete flag offensive edit

answered 2010-03-17 16:47:30 +0800

xadim gravatar image xadim
61 1

updated 2010-03-17 16:56:27 +0800

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

link publish delete flag offensive edit

answered 2010-03-17 17:14:14 +0800

rotkad gravatar image rotkad
18

I'm working on it, 'll get you know if I only find a solution.

link publish delete flag offensive edit

answered 2015-07-13 05:14:17 +0800

bhapux gravatar image bhapux
1

can you share your project please?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-02-14 20:54:15 +0800

Seen: 2,384 times

Last updated: Jul 13 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More