How to read uploaded file details in Jersey

gihan-maduranga

I have implemented REST service for upload multiple files into server.But the problem was that i can not get file details if i use FormDataMultiPart in the REST service.I can get the file content.like wise i tried to get file details like following and it gave me an error saying not supported.

    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public void upload(FormDataMultiPart formParams)
    {
        Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields();

       //Assume i am sending only files with the request

        for (List<FormDataBodyPart> fields : fieldsByName.values())
        {
            for (FormDataBodyPart field : fields)
            {

                InputStream is = field.getEntityAs(InputStream.class);
                String fileName = field.getName();
                field.getMediaType();
               //Those work perfectly

    //This gave me an error
  FormDataContentDisposition f=field.getEntityAs(FormDataContentDisposition   .class);
    System.out.println(f.getFileName());

            }
        }
    }

Please let me know how can i get files details like type,name,size for each uploaded files if use FormDataMultiPart.

gihan-maduranga

I was able to access file details finally here is the code snippet.

@POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public void upload(FormDataMultiPart formParams)
    {
        Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields();

       //Assume i am sending only files with the request

        for (List<FormDataBodyPart> fields : fieldsByName.values())
        {
            for (FormDataBodyPart field : fields)
            {

                InputStream is = field.getEntityAs(InputStream.class);
                String fileName = field.getName();
                field.getMediaType();


   //This working fine
  FormDataContentDisposition f=field.getFormDataContentDisposition();
  System.out.println(f.getFileName());

            }
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jersey: read uploaded file as JSON

From Dev

How to Read Contents of an Uploaded File

From Dev

How to uploaded and read text file in JSF and PrimeFaces?

From Dev

uploaded file details in html table

From Dev

how to read uploaded files

From Dev

how can I read from an uploaded text file

From Dev

How to read uploaded file that triggered lambda execution directly?

From Dev

Read uploaded JSON file in Rails

From Dev

How to read opened file and display content in Eclipse Master Details block?

From Dev

How can I read and change details of file in nodejs?

From Dev

How to read the details of particular file using c#

From Dev

How to check if a file was uploaded?

From Dev

PHP - Cannot read uploaded temporary file

From Dev

Oracle Apex - Read contents of an uploaded txt file

From Java

How to read an uploaded CSV file using Julia, Pluto.jl & PlutoUI.jl's FilePicker element

From Dev

Sails.js Skipper: How to read the uploaded file stream during upload?

From Dev

hello guys does someone know how to read a file uploaded by a user in discord.py

From Dev

Sails.js Skipper: How to read the uploaded file stream during upload?

From Dev

How to get uploaded file name?

From Dev

how to permission uploaded file correctly

From Dev

How to checksum the file to be uploaded with javascript?

From Dev

How to test that a file is uploaded in a controller?

From Dev

How to check on Rackspace if the file is uploaded or not?

From Dev

How to preview uploaded file in AngularJS

From Dev

How to empty the uploaded file list?

From Dev

How to checksum the file to be uploaded with javascript?

From Dev

How to store a file uploaded with vichUploaderBundle?

From Dev

How to parse uploaded Excel file?

From Dev

Read the JSON file in the Jersey sources folder

Related Related

  1. 1

    Jersey: read uploaded file as JSON

  2. 2

    How to Read Contents of an Uploaded File

  3. 3

    How to uploaded and read text file in JSF and PrimeFaces?

  4. 4

    uploaded file details in html table

  5. 5

    how to read uploaded files

  6. 6

    how can I read from an uploaded text file

  7. 7

    How to read uploaded file that triggered lambda execution directly?

  8. 8

    Read uploaded JSON file in Rails

  9. 9

    How to read opened file and display content in Eclipse Master Details block?

  10. 10

    How can I read and change details of file in nodejs?

  11. 11

    How to read the details of particular file using c#

  12. 12

    How to check if a file was uploaded?

  13. 13

    PHP - Cannot read uploaded temporary file

  14. 14

    Oracle Apex - Read contents of an uploaded txt file

  15. 15

    How to read an uploaded CSV file using Julia, Pluto.jl & PlutoUI.jl's FilePicker element

  16. 16

    Sails.js Skipper: How to read the uploaded file stream during upload?

  17. 17

    hello guys does someone know how to read a file uploaded by a user in discord.py

  18. 18

    Sails.js Skipper: How to read the uploaded file stream during upload?

  19. 19

    How to get uploaded file name?

  20. 20

    how to permission uploaded file correctly

  21. 21

    How to checksum the file to be uploaded with javascript?

  22. 22

    How to test that a file is uploaded in a controller?

  23. 23

    How to check on Rackspace if the file is uploaded or not?

  24. 24

    How to preview uploaded file in AngularJS

  25. 25

    How to empty the uploaded file list?

  26. 26

    How to checksum the file to be uploaded with javascript?

  27. 27

    How to store a file uploaded with vichUploaderBundle?

  28. 28

    How to parse uploaded Excel file?

  29. 29

    Read the JSON file in the Jersey sources folder

HotTag

Archive