如何通过单击 XPage 上的按钮将附件内容读入数组或字符串?
How to read an attachment content into an array or String by clicking a button on XPage?
我有一个带有文件 Upload/Download 控件的 XPage,它显示了我的附件。我需要通过单击按钮将 first 文件附件(名称不是 known/random)的内容读入字符串 var 或数组。
我不确定 XMLHttpRequests() 是否可以在 XPage 上工作,或者是否有标准的 XPages 控件可以做到这一点?
我只需要阅读内容。 (用户不需要直接与附件交互(select/save/other UI 操作))。
您需要弄清楚 "first" 是什么意思:最早的、最先连接的、字母表中的第一位? Domino 不保证顺序。您可以在求值语句中使用 @AttachmentNames
。然后,您可以使用该名称通过使用以下语法的休息调用直接从浏览器访问该附件:
http(s)://[yourserver]/[application.nsf]/[viewname|0]/[UNID| ViewKey]/$File/[AttachmentName]?Open
详情请见this blog entry。
如果你想在服务器端处理它,那么你可以使用 document.getAttachment().
工作示例:
importPackage(java.net);
importPackage(java.io);
var valString:String = "";
var nrt:NotesRichTextItem=document1.getDocument().getFirstItem('Body');
if (nrt!=null){
var eos:java.util.Vector = nrt.getEmbeddedObjects();
if (!eos.isEmpty()) {
var eo:NotesEmbeddedObject = eos.get(0);
var inputReader:BufferedReader = new BufferedReader(new InputStreamReader(eo.getInputStream(), "UTF-16"));
while ((inputLine = inputReader.readLine()) != null) {
valString+=inputLine + "<br>";
}
if (inputReader != null){inputReader.close();}
eo.recycle();
}
}
return valString;
我有一个带有文件 Upload/Download 控件的 XPage,它显示了我的附件。我需要通过单击按钮将 first 文件附件(名称不是 known/random)的内容读入字符串 var 或数组。
我不确定 XMLHttpRequests() 是否可以在 XPage 上工作,或者是否有标准的 XPages 控件可以做到这一点?
我只需要阅读内容。 (用户不需要直接与附件交互(select/save/other UI 操作))。
您需要弄清楚 "first" 是什么意思:最早的、最先连接的、字母表中的第一位? Domino 不保证顺序。您可以在求值语句中使用 @AttachmentNames
。然后,您可以使用该名称通过使用以下语法的休息调用直接从浏览器访问该附件:
http(s)://[yourserver]/[application.nsf]/[viewname|0]/[UNID| ViewKey]/$File/[AttachmentName]?Open
详情请见this blog entry。
如果你想在服务器端处理它,那么你可以使用 document.getAttachment().
工作示例:
importPackage(java.net);
importPackage(java.io);
var valString:String = "";
var nrt:NotesRichTextItem=document1.getDocument().getFirstItem('Body');
if (nrt!=null){
var eos:java.util.Vector = nrt.getEmbeddedObjects();
if (!eos.isEmpty()) {
var eo:NotesEmbeddedObject = eos.get(0);
var inputReader:BufferedReader = new BufferedReader(new InputStreamReader(eo.getInputStream(), "UTF-16"));
while ((inputLine = inputReader.readLine()) != null) {
valString+=inputLine + "<br>";
}
if (inputReader != null){inputReader.close();}
eo.recycle();
}
}
return valString;