关闭Dropzone.js中的autoProcessQueue会导致提交空文件

时间:2014-04-28 15:52:09

标签: java struts dropzone.js

我正在使用Dropzone.js将图像上传到Struts 1应用程序,作为发送消息的一部分。如果我允许Dropzone自动处理每个文件,那么它会被正确地传递给Action,我可以将它保存到磁盘。

但是,必须推迟此过程,以便作者在决定发送消息之前可以验证其消息/附件的内容。如果我将autoProcessQueue设置为false,然后尝试通过调用processQueue()或表单的提交按钮的按钮稍后上传,我的Action只会收到一个空文件。

的struts-config.xml:

<form-bean name="patientPortalAttachmentUploadForm" type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="attachment" type="org.apache.struts.upload.FormFile" />
</form-bean>
...
<action     path="/patient/portalmsg/send/attachments"
            type="com.communitect.ui.UploadAction"
            name="patientPortalAttachmentUploadForm"
            scope="request"
            parameter="portalmsg"
           input="/patient_view.jsp">
  <set-property property="secure" value="true"/>
  <forward name="success" path="/patient/view.do" redirect="true"/>
</action>

JSP页面:

<html:form action="/patient/portalmsg/send/attachments" 
    styleClass="dropzone"   
    styleId="dropzone">
  <html:button styleId="submit-all">Submit all files</html:button> 
</html:form>

....

    Dropzone.options.dropzone = {
    maxFiles: 2,
    addRemoveLinks:true,
    autoProcessQueue:false,
    paramName: "attachment",
    init: function() {
      var submitButton = document.querySelector("#submit-all")
          myDropzone = this; // closure

      submitButton.addEventListener("click", function() {
        myDropzone.processQueue(); // Tell Dropzone to process all queued files.
      })
    }

};

UploadAction.java

public final class UploadAction extends CustomAction
{
   @Override
   protected ActionForward executePostUser(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    User user ) throws IOException, ServletException, JSONException
   {
        DynaValidatorForm patientPortalAttachmentUploadForm = (DynaValidatorForm) form;

        FormFile file = (FormFile) patientPortalAttachmentUploadForm.get( "attachment" );
        System.out.println("AttachmentName: " + file.getFileName() );

我理解文档的方式,延迟文件的处理不应该导致此插件的功能和处理文件的方式发生任何其他变化。

感谢您的帮助。

0 个答案:

没有答案