title: Uploading a file on Angular 5 and send it to Java Spring Back End
body: <p>I have a problem on my app. I upload a file on Angular 5 but I can't give to my Java Spring Back end in order to insert it to a database.</p>
  
  <p>I receive a 500 error when I try to send the <code>frmData</code> to Java Controller.</p>
  
  <p>Does any one has a solution? Here is my code :</p>
  
  <p>my component .html :</p>
  
  <pre><code>&lt;ng-container&gt;
    &lt;input type="file" id="uploadFile" multiple 
           (change)="getFileDetails($event.target.file)"&gt;
  &lt;/ng-container&gt;&lt;/div&gt;
  </code></pre>
  
  <p>my component .ts :</p>
  
  <pre><code>getFileDetails (e) {
    //console.log (e.target.files);
    for (var i = 0; i &lt; e.target.files.length; i++) {
      this.myFiles.push(e.target.files[i]);
    }
  }
  
  addFollowUp1() {            
    const frmData = new FormData();
  
    for (var i = 0; i &lt; this.myFiles.length; i++) {
      frmData.append("file", this.myFiles[i]);
    }
  
    this.followUpService.addFollowUpAttachment(frmData).subscribe();
  }
  </code></pre>
  
  <p>And my Service.ts :</p>
  
  <pre><code>public addFollowUpAttachment(file: FormData): Observable&lt;any&gt; {
    return this.http.post('/SV-AUD/api/attachment/addAttachment', file );
  }
  </code></pre>
  
  <p>On java Back-end here is the controller :</p>
  
  <pre><code>@Controller
  @RequestMapping("/attachment")
  public class AttachmentController {
  
    @Autowired
    private AttachmentService attachmentService;
  
    @RequestMapping(value = "/addAttachment", method = RequestMethod.POST)
    @ResponseBody
    public void addFollowUpAttachment(@RequestParam("file") MultipartFile files) throws ApcException {    
      System.out.println("test");
      attachmentService.addFollowUpAttachment(files);    
    }    
  }
  </code></pre>
  
  <p>Thanks !</p>