John Glabb John Glabb - 1 year ago 76
Javascript Question

Is there a way to change fileupload control file name on submit

Here is my simple xPage:

<?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>


I want on Submit/Save that it saves fileselected in RichText field but with custom name. In other words whatever user selects to upload I want it be custom name as a file attachment in Notes Document. E.g. user uploads MyPicture.jpg then on Submit/Save it adds the file as an attachment to Notes document but with other name, e.g. Picture1.jpg

Answer Source

Yes, you can change attachment's name on submit. Use fileUpload's property filename

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

enter image description here