2
最终用户可以在Visualforce页面上载文件。在后端,我需要创建一个允许的文件扩展名列表,并将用户限制在该列表中。我如何创建扩展列表并验证它?很感谢任何形式的帮助。在Apex中验证文件扩展名
最终用户可以在Visualforce页面上载文件。在后端,我需要创建一个允许的文件扩展名列表,并将用户限制在该列表中。我如何创建扩展列表并验证它?很感谢任何形式的帮助。在Apex中验证文件扩展名
你不需要顶点?
<apex:inputFile>
有accept
您可以使用的参数。请记住,这将检查contentType,而不是扩展名(这是更正确的方法来做到这一点)。
如果你仍然想在apex验证 - 可能是这样的?
String fileName = 'foobar.xls';
Set<String> acceptedExtensions = new Set<String> {'.doc','.txt', '.jpg'};
Boolean found = false;
for(String s : acceptedExtensions){
if(found = fileName.endsWith(s)){ // yes, there's only one "=", I do want assignment here
break;
}
}
if(!found){ // after the whole loop it's still false?
ApexPages.addMessage(...);
}
谢谢!这很有帮助。 – Nish