Java OFBiz中的文件上传? [英] File Upload in Java OFBiz?

查看:99
本文介绍了Java OFBiz中的文件上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以上传文件的表单

I have a form that has an option for uploading file

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

事件功能正常运行,但是我还需要将文件也上传到服务器,并将该文件的详细信息上传到名为"documents"的表中,但是我不知道该怎么做,因此我搜索了Web,但只有我使用ftl找到,我还想控制已定义文件的文件类型,我想在添加用户故事时以表格形式将那些文件类型显示为允许的文件. 如有任何指导和帮助,谢谢.

The event function is working properly, but i need to upload the file also to the server and details of that file to the table named as 'documents', but i don't know how to do that, i searched throw the web but only i found using ftl, also want to control the file type of defined file that i want to display those file types as allowed file in form during adding user story. For any guide and help thanks.

推荐答案

请查看OFBiz内容管理器中的图像上传功能.

Please have a look at the image upload functionality in the OFBiz content manager.

有一个表格

<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中的相应请求

The corresponding request in the 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中的服务名称将您带到服务方法

The service name in services.xml lead you to the service method

<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类型.

You will find some other functionality like dealing with the mime type there.

这篇关于Java OFBiz中的文件上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆