Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:38:09+00:00 2026-05-26T20:38:09+00:00

My Spring application passes image file to Jersey application to get rid of all

  • 0

My Spring application passes image file to Jersey application to get rid of all image manipulation tasks.

On receiving image, the Jersey application should save the image after several manipulations (crop, resize etc) and return image url.

For this, the Spring application has the below form in a JSP file:

<form method="POST" action="/asdf" enctype="multipart/form-data">
    <input type="file" name="fstream"></input>
    <input type="submit" value="Upload"/>
</form>

In my spring controller, I get DataInputString using:

DataInputStream in = new DataInputStream(request.getInputStream());

What would be an easy approach to carry out the desired action mentioned above?
How about converting it to BufferedImage in Spring app, POST it to the Jersey app, carry out required manipulations and save the image?

If that’s fine, how do I convert DataInputStream to BufferedImage?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:38:10+00:00Added an answer on May 26, 2026 at 8:38 pm

    Since there was no answer …

    1. I obtained byte array from submitted form data
    2. Sent an object with byte[] being one of the attribute to REST server
    3. On server side, I converted byte[] to BufferedImage which I scaled (using ImgScalr API) as required, and saved it.

    @Path(“/image”)
    public class ImageController {

    @PUT
    @Path("upload/{fileName}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response upload(@PathParam("fileName") String fileName, FileBytes fileBytes){
        byte[] bytearray = fileBytes.getFileBytes();
        int len = bytearray.length;
        if(len>0){
            try {
                int width=0, height=0, edge=0, px1=0, px2=0;
                InputStream in = new ByteArrayInputStream(bytearray);
                BufferedImage image = ImageIO.read(in);
    
                File file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_ORIGINAL+fileName+".jpg");
                ImageIO.write(image, "png", file); //saving original image
    
                width = image.getWidth();
                height = image.getHeight();
    
                                //scaling as required
                if(height>width){
                    px2 = (height-width)/2+1;
                    edge = width;
                }else if(width>height){
                    px1 = (width-height)/2+1;
                    edge = height;
                }else{
                    edge = width;
                }
    
                                //using ImgScalr API to get scaled image
                image = image.getSubimage(px1, px2, edge, edge);                
                image = Scalr.resize(image, 120);
                file = new File(Constants.PATH_TO_IMAGES+Constants.PATH_THUMBNAIL+fileName+".jpg");
                ImageIO.write(image, "png", file); //saving scaled image
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return Response.status(Status.OK).entity("Filename:"+fileName).build();     
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my spring application working, following a guy who posted an
In my application's web.xml I originally had Jersey configured as follows: <servlet> <servlet-name>jersey-servlet</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
Spring java- quartz schedular application I want to load .property file dynamically passed throw
I'm developing disk catalog application that requires me to get file icons using file
I need some help here.. Im trying to save a canvas image after drawing..
In my Java spring application I have a form with Region drop down. On
On my MVC spring application I send a form to a page using post
I develop a simple Spring application which is my university task. There are 3
I have developed a spring application, I want to configure it with apache log4j,
In our Spring application we use clustered Hibernate Search with ActiveMQ which sets up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.