gpt4 book ai didi

java - Java OFBiz 中的文件上传?

转载 作者:行者123 更新时间:2023-11-30 03:32:25 24 4
gpt4 key购买 nike

我有一个带有上传文件选项的表单

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

请求 map :

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

事件函数工作正常,但我需要将文件上传到服务器,并将该文件的详细信息上传到名为“文档”的表,但我不知道该怎么做,我搜索了抛出web,但只有我发现使用 ftl,还想控制已定义文件的文件类型,我想在添加用户故事期间将这些文件类型显示为表单中允许的文件。对于任何指导和帮助,谢谢。

最佳答案

请查看 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 类型。

关于java - Java OFBiz 中的文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28713490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com