1

I am trying to upload a file using jar-rs and postman.

  @POST  
  @Path("/upload")  
  @Consumes(MediaType.MULTIPART_FORM_DATA)  
  public Response uploadFile( @DefaultValue("true") 
            @FormDataParam("enabled") boolean enabled,
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) {


        String uploadedFileLocation = "D://uploadedFiles/" + 
                                                fileDetail.getFileName();
        System.out.println(uploadedFileLocation);
}

But while excuting webservice I am getting fileDetail parameter as null.
Why it is null?

OnkarG
  • 267
  • 1
  • 3
  • 16
  • You have mapped the same parameter to two variables here i.e uploadedInputStream & fileDetail. `@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail` – piy26 May 15 '18 at 10:30
  • Please check this link: https://stackoverflow.com/a/25889454/540195 – Amit May 15 '18 at 10:35
  • In refererence example they have also given same name – OnkarG May 15 '18 at 10:35
  • @Amit I have refered same link – OnkarG May 15 '18 at 10:36
  • what about your request code? You have to send exact same name "file" MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", fileContent); – Amit May 15 '18 at 10:40
  • @Amit I am using postman – OnkarG May 15 '18 at 10:42

0 Answers0