Domanda

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" />
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top