Note that there are some explanatory texts on larger screens.

plurals
  1. POCopying a file from a temporary tomcat folder using java
    primarykey
    data
    text
    <p>Basically my problem is a that I need to copy an uploaded file (which is placed in a temporary folder on my server providers Tomcat ie. not a local Tomcat).</p> <p>The code I'm using works when I deploy my project on my local machine but stops working when I deploy it live. I've found out that it has something to with my permissions in java.policy.</p> <p>What I need to find out is how do I get access to the folder in which Tomcat stores the temporary file using Java.</p> <p>When reading catalina.out this is the clue that the log gives me.</p> <p>/usr/local/tomcat/work/Catalina/project name here/context of project here/upload_490341a6_12b1d397355_76ce_00000001.tmp</p> <p>I'm thinking somewhere along the lines (note: this is not an actual method :P )</p> <p>ServletActionContext.getContext().getSuperHiddenTemporaryCatalog();</p> <p>The code snippet at the bottom has one flaw.</p> <p>sourceFile and targetFile points to the same directory at the moment.</p> <p>I want the sourceFile path to be the temporary tomcat-folder.</p> <p>Thanks in advance! :D</p> <hr> <pre><code>public String saveImage(File file, String uploadedFileName) { String path = ServletActionContext.getServletContext().getRealPath("images"); System.out.println(path); String fullFileName = path + "/" + uploadedFileName; System.out.println(fullFileName); boolean successful = false; try { File sourceFile = new File(fullFileName); File targetFile = new File(path + "/" + uploadedFileName); InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(targetFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) &gt; 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (Exception e) { successful = false; e.printStackTrace(); } if (successful) { return "context of project/images/" + uploadedFileName; } else { return ""; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload