Path and name of uploaded file

2
I need to find (in a java action) the path and name of a file chosen by the user to upload (I want to derive another filename from it and save it in the same client-side directory - it contains errors found in processing the file selected). I wrote this: File javaFile = Core.getFileDocumentContentAsFile (dataFile); String inputFileName = javaFile.getPath(); System.out.println (inputFileName); OutputStream stream = new FileOutputStream (new File (inputFileName + "-error.csv")); errorWriter = new BufferedWriter (new OutputStreamWriter (stream)); but Mendix created the new file not in the client-side directory the user chose the file from, but in a server-side directory in WEB-INF which it was copied to when uploaded to the server. Furthermore then filename is not that selected by the user but an arbitrary number which Mendix seems to have allocated. Can I get the original path and name of the uploaded file, and is there a problem with creating and writing to a new file on the client machine?
asked
1 answers
6

The original file name is stored in the 'Name' attribute of the FileDocument.

We recommend you to use the method Core.getFileDocumentContent() and to use the inputstream to store a new FileDocument with the same content via Core.storeFileDocumentContent. When a user uploads a file, it will be stored on the server running the Mendix Runtime. The file name in the file system is defined by the Runtime and this file name is not for public use. When you create a file (by uploading, via Core.storeFileDocumentContent or via an own method in Java), the file is created on the server, never on the client! A file created via Core.storeFileDocumentContent can be downloaded by users.

The original file name is stored in the Name attribute as I said, but the original path is not stored in any field by the Mendix Runtime due to security reasons.

answered