我有一个表格,可以选择上传文件
<form type="upload" name="myForm" target="rgUsrStory">
<field name="st_title" title="${uiLabelMap.uStoryTitle}"><text/></field>
<field name="upload_file" title="${uiLabelMap.UploadFile}"><file/></field>
<field name="submitButton" title="${uiLabelMap.submit}"><submit/></field>
</form>
请求地图:
<request-map uri="rgUsrStory">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.webapp.control.usrStory" invoke="rgUsrStory" />
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="login"/>
</request-map>
事件功能正常,但我需要将文件上传到服务器,并将该文件的详细信息上传到名为&#39; documents&#39;的表中,但我不知道如何这样做,我搜索抛出网页,但只有我发现使用ftl
,也想控制我想在添加用户故事期间显示那些文件类型作为允许文件的已定义文件的文件类型。
任何指导和帮助谢谢。
答案 0 :(得分:2)
请查看OFBiz内容管理器中的图片上传功能。
有一个表格
<form name="ImageUpload" target="uploadImage" title="" type="upload" default-map-name="currentValue"
header-row-style="header-row" default-table-style="basic-table">
<field name="dataResourceId" title="${uiLabelMap.ContentDataResourceId}"><display/></field>
<field name="dataResourceTypeId" ><hidden/></field>
<field name="objectInfo" title="${uiLabelMap.ContentUploadedFile}"><display /></field>
<field name="imageData" entity-name="ImageDataResource" title="${uiLabelMap.ContentFile}"><file/></field>
<field name="submitButton" title="${uiLabelMap.CommonUpload}" widget-style="smallSubmit"><submit button-type="button"/></field>
</form>
controller.xml中的相应请求
<request-map uri="uploadImage">
<security auth="true" https="true"/>
<event invoke="persistContentAndAssoc" path="" type="service"/>
<response name="success" type="request" value="UploadImage"/>
<response name="error" type="view" value="UploadImage"/>
</request-map>
services.xml中的服务名称将引导您进入服务方法
<service name="persistContentAndAssoc" engine="java" transaction-timeout="7200"
location="org.ofbiz.content.ContentManagementServices" invoke="persistContentAndAssoc" auth="true">
<description>Create a Content, DataResource and/or ContentAssoc</description>
<permission-service service-name="genericContentPermission" main-action="CREATE"/>
...
</service>
在org.ofbiz.content.ContentManagementServices#persistContentAndAssoc
中,
ByteBuffer imageDataBytes = (ByteBuffer) context.get("imageData");
(相应的表格字段)。
你会发现一些其他功能,比如在那里处理mime类型。