title: How to upload image with a product object through Hibernate in Spring MVC
body: <p>I have an angular form where I fill fields for a product and then I select images. I've added following configuration in AppConfig in SpringMVC project to enable MultiPart Files.</p>
  
  <pre><code>@Bean(name = "multipartResolver")
  public CommonsMultipartResolver multipartResolver() {
      CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
      multipartResolver.setMaxUploadSize(1000000);
      return multipartResolver;
  }
  </code></pre>
  
  <p>I've also added a transient field in my Product Model for images like this:</p>
  
  <pre><code>@Transient
  private List&lt;MultipartFile&gt; productImages;
  </code></pre>
  
  <p>Since I want to receive the Product object separately inside the controller I'm using <code>@RequestPart</code> to fetch both separately like this:</p>
  
  <pre><code>@RequestMapping(value = "save", method = RequestMethod.POST)
  public ResponseEntity addProduct(@Valid @RequestPart Product product, @RequestPart MultipartFile[] images, BindingResult bindingResult, HttpServletRequest 
  }
  </code></pre>
  
  <p>And on the frontend inside Angular, I'm trying to use <code>FormData</code> to help with this.</p>
  
  <pre><code>let formData = new FormData();
  
  formData.append('product', new Blob([JSON.stringify(this.product)],{ type: "application/json" }));
  // I iterate and append all the images like this
  formData.append('image[]', this.images, this.images.name);
  
  this.http.post(this.appService.getApiUrl() + "api/product/save/", product);
  </code></pre>
  
  <p>The problem is that whenever I submit the form, I get this exception as a response:
  <strong>HTTP Status 415 – Unsupported Media Type</strong></p>
  
  <p>I had an HttpInterceptor that appended an <em>application/json</em> header for <em>Content-Type</em>, I removed it because of it I was getting <strong>HTTP Status 400 – Bad Request</strong>.
  At this point, I do not know what's the problem, I don't know how to debug the front facing spring mvc stuff, I can only debug through breakpoints within a controller method but the problem arises well before.</p>