title: Spring Rest Controller with Byte Array file
body: <p>I am trying to send a byte array of a file content from angular to the rest api. But I am getting Http 403 forbidden. I don't have any security enabled. I am not sure what I am doing wrong. I tried couple of different MIME types. The below is the http post from angular js and the $scope.encoded_file has the file in byte array. </p>
  
  <pre><code>$http({
    method:'POST',
    url:'http://localhost:9200/docupload',
    data:{'content':$scope.encoded_file,'name':'test','type':'pdf'},
    headers:{'Content-Type':'application/octet-stream'}
    }).success(function(){}); 
   };
  </code></pre>
  
  <p><strong>DocUploadService</strong></p>
  
  <pre><code>  @RestController
    public class DocUploadService {
  
    @RequestMapping(value="/docupload",method={RequestMethod.GET,RequestMethod.POST},consumes="application/octet-stream")
    public String UploadDocuments(@RequestParam(value="content")byte[] content,@RequestParam(value="type") String type,@RequestParam(value="name") String name) throws IOException
      {
          System.out.println("****Inside DocUpload*****");}}
  </code></pre>
  
  <p>The request doesnt reach to the service of course and I dont know why I am getting 403. Any idea?</p>
  
  <p>Request Headers:
  <a href="https://i.stack.imgur.com/REYVY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/REYVY.png" alt="enter image description here"></a></p>
  
  <p>Added @CrossOrigin in before the service method but still no luck</p>
  
  <p>Did the below added the CrossOrigin to the controller method.</p>
  
  <pre><code>public class DocUploadService {
  @CrossOrigin(origins = "http://localhost:9200")
  @RequestMapping(value="/docupload",method={RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS,RequestMethod.PUT},consumes="application/octet-stream")
  </code></pre>
  
  <p>Also, added global CORS registry. </p>
  
  <pre><code> @EnableWebMvc
   public class WebMVCconfig extends WebMvcConfigurerAdapter {
  
   @Override
   public void addCorsMappings(CorsRegistry registry) {
      // TODO Auto-generated method stub
      registry.addMapping("/docupload")
      .allowedOrigins("http://localhost:9200")
      .allowedMethods("POST", "GET","OPTION","PUT");
      super.addCorsMappings(registry);
  
  }
  </code></pre>