title: org.springframework.web.multipart.MultipartException: Current request is not a multipart request
body: <p>I try to add an image from item details page. The image added successfully, but when I try to display the image at the itemdetails page I got the exception <code>org.springframework.web.multipart.MultipartException: Current request is not a multipart request</code></p>
  
  <p>JSP:</p>
  
  <pre><code>&lt;div class="panel panel-info"&gt;
      &lt;%-- &lt;form:form method="POST" name="moduleForm1" modelAttribute="DocumentEntity"&gt; --%&gt;
      &lt;input type="hidden" name="selectedId3" value="${DocumentEntity.documentSeq}"  /&gt;
      &lt;div class="panel-heading clearfix"&gt;
          &lt;div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"&gt;
              &lt;h4 class="pull-left"&gt;Item Images&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="col-lg-1 col-md-1 col-sm-12 col-xs-12"&gt;
               &lt;h4 class="pull-left"&gt;Select File&lt;/h4&gt;
           &lt;/div&gt;
           &lt;div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"&gt;
           &lt;%-- &lt;html:file name="ItemForm" property="desc" styleClass="form-control"&gt;&lt;/html:file&gt; --%&gt;
           &lt;input type="file" name="file" id="file" enctype="multipart/form-data"/&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>AttachmentService:</p>
  
  <pre><code>    package com.groups.attachements;
  
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.sql.SQLException;
      import java.util.ArrayList;
      import java.util.Date;
      import java.util.List;
  
      import org.hibernate.Query;
      import org.hibernate.Session;
  
      import com.groups.GroupsConstants;
      import com.groups.GroupsCustomeException;
      import com.groups.GroupsFileManager;
      import com.groups.GroupsObjectImpl;
      import com.groups.GroupsUtils;
      import com.groups.dao.DropDownListBean;
      import com.groups.dao.GroupsBaseAccess;
      import com.groups.dao.GroupsDAOContext;
      import com.groups.dao.GroupsDAOContextFactory;
      import com.groups.spring.annotations.GroupsRequest;
  
      @GroupsRequest
      public class AttachmentServiceImpl extends GroupsObjectImpl implements
              AttachmentService
      {
          String appID = "IMS";
  
          String sponsorID;
  
          long sponsorSeq;
  
          String moduleID;
  
          DocumentEntity documentEntity;
  
          public static final String ITEM_ENTITY = "ITEM";
  
          public AttachmentServiceImpl()
          {
              appID = GroupsConstants.getApplicationDependable().getAppID();
  
          }
  
          @Override
          public Long createAttachment(InputStream is, String moduleType,
                  String moduleRecordSeq, String createUser, String fileName)
                  throws IOException, Exception
          {
  
              ensureSponsorIDVal();
  
              String homeDir = GroupsConstants.getApplicationDependable()
                      .getAttachmentsDir(sponsorID);
  
              String attachFileDir = moduleType + File.separator + moduleRecordSeq;
  
              homeDir = homeDir + File.separator + attachFileDir;
  
              File parentDir = new File(homeDir);
  
              GroupsFileManager.createDir(parentDir.getAbsolutePath());
  
              File uploadingFile = new File(parentDir, fileName);
  
              FileOutputStream fos = null;
  
              try
              {
  
                  fos = new FileOutputStream(uploadingFile);
  
                  GroupsFileManager.write(is, fos);
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              finally
              {
                  if (fos != null)
                  {
                      fos.close();
                  }
              }
  
  
  
              DocumentEntity ae = new DocumentEntity();
  
              int dcid = GroupsUtils.generateUniqueId();
  
              ae.setFileName(fileName);
  
              String extension = "";
  
              int i = fileName.lastIndexOf('.');
              int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
  
              if (i &gt; p)
              {
                  extension = fileName.substring(i + 1);
              }
  
              String docid = ("FS" + dcid);
  
              String documentId = ("FS" + dcid + "." + extension);
  
              ae.setDocumentId(documentId);
  
              String path = attachFileDir + File.separator + docid;
  
              ae.setModuleRecordSeq(moduleRecordSeq);
              ae.setModuleType("ITEM_ENTITY");
  
              ae.setAppID(appID);
  
              ae.setVersionNo(1);
  
              ae.setFileSystem("FS");
  
              ae.setPath(path);
  
              // String sponsorSeq =
              // nullToEmptyString(DocumentEntity.getSponsorSeq());
  
              ae.setSponsorSeq(sponsorSeq);
  
              ae.setCreateUser(createUser);
              // Date createDate=now();
              ae.setCreateDate(new Date());
  
              Session s = getSessionHibernate();
              s.save(ae);
              s.flush();
  
              return ae.getDocumentSeq();
  
  
  
  
  
          }
  
          private String ensureSponsorIDVal() throws SQLException
          {
              sponsorSeq = GroupsUtils.getLong(GroupsUtils.getSponsorSeq());
  
              if (sponsorID == null)
                  sponsorID = GroupsUtils.getSponsorID(sponsorSeq + "",
                          getConnection());
  
              return sponsorID;
  
          }
  
          @Override
          public void createAttachment(File file, String moduleType,
                  String moduleRecordSeq, String createUser, String fileName)
                  throws IOException, Exception
          {
              InputStream is = null;
  
              try
              {
                  if (file != null)
                      is = new FileInputStream(file);
  
                  createAttachment(is, moduleType, moduleRecordSeq, createUser,
                          fileName);
              }
              catch (Exception ex)
              {
                  ex.printStackTrace();
                  throw ex;
              }
              finally
              {
                  if (is != null)
                      is.close();
              }
  
          }
  
          @Override
          public List&lt;DocumentEntity&gt; getAttachments(String moduleType,
                  String moduleRecordSeq) throws IOException, Exception
          {
              String query = " from DocumentEntity where moduleType='" + moduleType
                      + "'and moduleRecordSeq='" + moduleRecordSeq
                      + "'and sponsor_seq='" + sponsorSeq + "' ";
              Query q = getSessionHibernate().createQuery(query);
  
              List&lt;DocumentEntity&gt; documentEntityBeans = q.list();
  
              return documentEntityBeans;
          }
  
          @Override
          public AttachmentEntity getAttachmentEntity(Long docSeq)
          {
              return null;
          }
  
          @Override
          public InputStream getAttachmentStream(long docSeq) throws IOException,
                  Exception
          {
  
              return null;
          }
  
          @Override
          public List&lt;AttachmentEntity&gt; getAttachmentEntity(String moduleType,
                  String moduleSeq)
          {
  
              return null;
          }
  
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    @Autowired
          AttachmentService attachmentService;
  
          @RequestMapping("/ItemDetailImageAdd.htm")
          public ModelAndView itemDetailImageAdd(@RequestParam("file")
          MultipartFile file, @RequestParam(value = "selectedId2", required = false)
          String itemSeq) throws Exception
          {
  
              InputStream is = file.getInputStream();
              String fileName = file.getOriginalFilename();
  
              if (fileName.length() == 0)
              {
                  // gce.add("error.importstudents.file.required");
  
                  throw new GroupsCustomeException(
                          "error.image.required");
              }
  </code></pre>
  
  <p>struts-config:</p>
  
  <pre><code> &lt;action path="/ItemDetailsSubmit"
                  type="com.groups.hms.items.action.ItemDetailsSubmitAction"
                  name="ItemForm"
                  scope="session"
                  validate="true"
                  input="/pages/items/ItemDetails.jsp"&gt;     
  
              &lt;exception
                  key="error.general"
                  className="com.groups.GroupsExceptionConfig"
                  type="com.groups.GroupsCustomeException"
                  handler = "com.groups.GroupsExceptionHandler" /&gt;
  
             &lt;forward name="viewDetails" path="/ViewItemDetails.do"/&gt;
       &lt;/action&gt; 
  </code></pre>