1

in am using ace:fileEntry component to upload a pdf file. my problem i dont know how to change the filename while uploading the document. The file gets uploaded with the originalfilename.I know that if i set useOriginalFilename=false, it would have a unique name, but I want that the file uploaded in the file system should have the custom filename which i want to pass.

My xhtml code is as below

<ace:fileEntry id="file-entry" label="Attachment"
                    absolutePath="STR_UPLOADED_FILES"
                    maxFileCount="1" 
                    maxFileCountMessage="Limited to 1 files uploaded concurrently." 
                    fileEntryListener="#{strformbean.fileuploadListener}" 

                    maxFileSize="6291456" 
                    maxFileSizeMessage="Submitted file is too large.Max size allowed is 6MB" 
                    maxTotalSize="6291456" 
                    maxTotalSizeMessage="Total size of submitted files is too large." 
                    required="false" 
                    requiredMessage="The file is required to submit this form." 
                    useOriginalFilename="true"  
                    useSessionSubdir="false" />
ZEE
  • 381
  • 1
  • 6
  • 20

1 Answers1

1

You sound like as if you expected that the temporary storage location of uploaded files is usable as a permanent storage location of uploaded files and you thus don't need to touch it. This is wrong! The location where uploaded files will initially end up is really temporary in order to save server memory usage. It will be cleaned at intervals or startup/shutdown.

In the listener method, you should be obtaining the content of the uploaded file yourself as InputStream or byte[] which you should write to the permanent storage location. During this step you have all the freedom to specify your own filename.

See also this closely related question about PrimeFaces <p:fileUpload> (whose sourcecode ICEfaces has for the major part stolen copypasted redistributed) Where is the p:fileUpload uploaded file saved and how do I change it? for a detailed answer how to deal with it properly.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • yes BalusC,i am aware that by default its a temporary location and during certain intervals , the file will be get cleaned up e.g during server startup. But in my case i have specified the absolute path "/STR_UPLOADED_FILES" which actually goes to my machine root directory. Files uploaded into this will not get cleaned up , as i have tested it, coz its not under the project deployment folder structure. – ZEE Jan 01 '13 at 06:40
  • This made me worried actually. As of now i will go ahead with the IOUtils.copy to copythefileto other location where ever i want, and i will delete the file uploaded initially from my code. Is this OK as per your experience ? . Please guide me. – ZEE Jan 01 '13 at 06:43
  • Yes, that's the way. It's also demonstrated as such in the linked detailed answer. You don't need to delete the file yourself, but if you're restrictive in temporary space, feel free to do so. – BalusC Jan 01 '13 at 12:28