<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Temporary file is not stored in a session subfolder</title><link>https://answers.axonivy.com/questions/2993/temporary-file-is-not-stored-in-a-session-subfolder</link><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;we are using the ch.ivyteam.ivy.scripting.objects.File object to create a temporary file, which we want to use as a source for a stream. This seems to work fine and we have no troubles in our development environment. &lt;/p&gt;
&lt;p&gt;In our productive environment, however, we expierence sometimes a "file not found" exception. As far as I know, the temporary files should be stored in a temp folder like /files/sessions/{sessionID}/ .&lt;/p&gt;
&lt;p&gt;In our environment, these files are not in a session subfolder but can be found directly in the folder /session/tempfileXYZ. We therefore assume that whenever we close a session, the whole tempfolder is deleted, which will result in our "file not found" exception for other users.&lt;/p&gt;
&lt;p&gt;Is there any way to enable that files will be stored in session folders again?&lt;/p&gt;
&lt;p&gt;Thx,&lt;/p&gt;
&lt;p&gt;Gerald&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2993/temporary-file-is-not-stored-in-a-session-subfolder" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 21 Nov 2017 08:39:52 -0500</lastBuildDate><item><title>Answer by Gerald</title><link>https://answers.axonivy.com/questions/2993/temporary-file-is-not-stored-in-a-session-subfolder/2995</link><description>&lt;p&gt;Hi there, &lt;/p&gt;
&lt;p&gt;we obviously got confused by the presented Link in our PDF Reader (which is without the session id). On the file level there is indeed a folder structure based on the session ids. &lt;/p&gt;
&lt;p&gt;But can anyone give me a hint what could be the reason why files from the temporary folder (delegated through the stream object) become invalid within a session? I'm using the following code to create the stream.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;            Ivy.log().info("Original Path: " + pathOrUrlToPdf);
            SecureRandom random = new SecureRandom();

            String tempFileName = "temp" + random.nextLong() + ".pdf";
            URL source = new URL(pathOrUrlToPdf);
            File tempFileIvy = new File(tempFileName, true);

            FileUtils.copyURLToFile(source, tempFileIvy.getJavaFile());

            returnPath = Ivy.html().fileref(tempFileIvy);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thx,&lt;/p&gt;
&lt;p&gt;Gerald&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gerald</dc:creator><pubDate>Tue, 21 Nov 2017 08:39:52 -0500</pubDate><guid>https://answers.axonivy.com/questions/2993/temporary-file-is-not-stored-in-a-session-subfolder/2995</guid></item></channel></rss>