How do you get the filename from the XPages FileUpload Control

放肆的年华 提交于 2019-12-08 03:30:04

问题


In XPages, in the file upload control, after a user selects a file but before it's saved how can you get the filename? I'm not interested in the path as I believe that's not getable due to security issues but I would like to get the filename and extension if at all possible.

Thanks!


回答1:


Actually you can get the file and fully manipulate it, read it, do whatever you want with it, its stored in the xsp folder on the server, to which you have read/write access... here is a code snippet that interacts with the file, I usually call from beforeRenderResponse...

var fileData:com.ibm.xsp.http.UploadedFile = facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('<INSERT ID OF UPLOAD CONTROL HERE (ie. fileUpload1)>'));

if (fileData != null) {
    var tempFile:java.io.File = fileData.getServerFile();
    // Get the path
    var filePath:String = tempFile.getParentFile().getAbsolutePath();
    // Get file Name
    var fileName:String = tempFile.getParentFile().getName();
    // Get the Name of the file as it appeared on the client machine - the name on the server will NOT be the same
    var clientFileName:String = fileData.getClientFileName();
}



回答2:


It sounds like you are referring to needing to get the data via CSJS, which you can do with the following code:

var filename = dojo.byId('#{id:fileUpload1}').value.split('\\').pop();



回答3:


These links should be able to help you.

http://www.bleedyellow.com/blogs/andyc/entry/intercepting_a_file_upload4?lang=en

http://www.bleedyellow.com/blogs/m.leusink/entry/processing_files_uploaded_to_an_xpage?lang=en



来源:https://stackoverflow.com/questions/11803158/how-do-you-get-the-filename-from-the-xpages-fileupload-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!