2016-08-03 56 views
2

這裏是我的簡單的XPage:有沒有辦法來改變FileUpload控件文件名上提交

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"> 
    <xp:this.data> 
     <xp:dominoDocument var="document1" formName="File Resource"></xp:dominoDocument> 
    </xp:this.data> 
    <xp:fileUpload id="fileUpload1" value="#{document1.FieldAttachment}"> 
    </xp:fileUpload> 

    <xp:button value="Save" id="button1"> 
     <xp:eventHandler event="onclick" submit="true" 
      refreshMode="complete" immediate="false" save="true"></xp:eventHandler> 
    </xp:button> 
</xp:view> 

我想在提交/保存它保存在富文本字段,但與自定義名稱fileselected。換句話說,無論用戶選擇上傳,我都希望它是自定義名稱作爲Notes文檔中的文件附件。例如。用戶上傳MyPicture.jpg,然後在提交/保存時將文件作爲附件添加到Notes文檔中,但是具有其他名稱,例如, Picture1.jpg

回答

3

是的,您可以在提交時更改附件的名稱。使用文件上傳的財產filename

<xp:fileUpload 
    id="fileUpload1" 
    value="#{document1.FieldAttachment}" 
    useUploadname="false" 
    filename="Picture1.jpg"> 
</xp:fileUpload> 

enter image description here

如果你想計算根據上傳的文件名附件名稱可以使用this.value.getClientFileName()得到原始文件名。

例如:添加前綴「Picture_」以原文件名

<xp:fileUpload 
    id="fileUpload1" 
    value="#{document1.FieldAttachment}" 
    useUploadname="false"> 
    <xp:this.filename><![CDATA[#{javascript: 
     var fileName = this.value.getClientFileName(); 
     return "Picture_" + fileName; 
    }]]></xp:this.filename> 
</xp:fileUpload> 
+0

謝謝你..這工作..我只是錯過了財產..對不起,愚蠢的問題 –

+1

不客氣。但這不是一個愚蠢的問題。例如,如何修改原始文件名並不是真正的自我解釋... –

相關問題