java - Java OFBiz 中的文件上传?

标签 java ofbiz

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

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

相关文章:

java - 尝试在 OfBiz 中保存任务时收到 FK 违规错误

使用sax解析器的java程序

java - 将数组字符串替换为其他数组字符串

java - Eclipse IDE 边栏(导航)缺失

tomcat - 自运行 ofbiz 后无法部署 war 文件?

ofbiz - 如何在 Apache OFBiz 最新版本 16.11.01 中创建新组件?

java - 如何使用 python 和 Java 运行 Docker?

java - 404带 Spring 3

java - Apache OFBiz 中的 Apache POI 异常

database - OFBiz 应用程序的不同部分可以连接到不同的数据库吗?