如何从 XPages FileUpload Control 获取文件名 [英] How do you get the filename from the XPages FileUpload Control

查看:22
本文介绍了如何从 XPages FileUpload Control 获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XPage 中,在文件上传控件中,在用户选择文件之后但在保存之前如何获取文件名?我对路径不感兴趣,因为我认为由于安全问题而无法获得该路径,但如果可能的话,我想获取文件名和扩展名.

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.

谢谢!

推荐答案

其实你可以得到这个文件并对其进行完全的操作、读取它,对它做任何你想做的事情,它存储在服务器上的 xsp 文件夹中,到哪个你有读/写访问权限...这里是一个与文件交互的代码片段,我通常从 beforeRenderResponse 调用...

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();
}

这篇关于如何从 XPages FileUpload Control 获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆