title: How to send file correctly using resteasy in angular?
body: <p>I have the current service in an angular 5 app:</p>
  
  <pre><code>const httpOptions = {
    headers: new HttpHeaders({ 'Accept': 'application/json', 'Content-Type': 'multipart/form-data' })
  };
  
  @Injectable()
  export class UploadService {
  
    constructor(private http: HttpClient) { }
  
    // file from event.target.files[0]
    uploadFile(url: string, file: File): Observable&lt;any&gt; {
  
      let formData = new FormData();    
      formData.append('upload', file, file.name);                
      return this.http.post(url, formData, httpOptions);        
    }
  }
  </code></pre>
  
  <p>And I have resteasy method in the java application:</p>
  
  <pre><code>@POST
  @Path("MyThing/Pic")
  @Consumes("multipart/form-data")
  @Produces("application/json")
  public void uploadImage(InputStream stream){
  
      try {
          byte[] buffer = new byte[stream.available()];
          stream.read(buffer);
  
          File targetFile = new File("xyz.png");
          OutputStream outStream = new FileOutputStream(targetFile);
          outStream.write(buffer);
          outStream.flush();
          outStream.close();
      } catch (IOException e) {
          // TODO throw!
          e.printStackTrace();
      }   
  }
  </code></pre>
  
  <p>The problem is that I need to know the file name in the server side, at least the file name suffix which is the type of the file. If someone upload jpeg I want save jpeg and not png as default for example.
  Is there a better way to send the file from 'multipart/form-data' and if yes what should be the definition of the server side method in this case ?
  thanks! </p>