Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
sending images from java webserver to client

i'm new to java web App i was trying to create simple chat webapp that send images to webserver then the server will send them to other client at first i had problem that the websocket wont send large data so i send my images using

http request

after encoding them to base64 then after i was able to decode it and store it,i was trying to seend it from the server to the other client

i did not find any solution the only way to send it to the other client is using websocket

this is the third day of searching and i'm thinking of given up since there is no resources for noobies

i saw alot of code but they was in high level i hope if some one have the answer of

How can i send the image to the client ?

please Try to explain it in a simple way

the javascript function responsible for sending the img

send=function () {
    
               var file =document.getElementById("image").files[0];
    
    
               var content_type ={
                   headers:{
                       "content-type" : "multipart/form-data"
                   }
               };
    
                   var formdata = new FormData();
                   formdata.append('image',file);
    
                   axios.post('AddImage',formdata,content_type)
                       .then(function (response) {
                           console.log(response);
                       })
                       .catch(function (error) {
                           console.log(error);
                       });
    
           }

the post method that send the file

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        Part file=request.getPart("image");



        InputStream in = file.getInputStream();
        byte[] Byte_file = new byte[in.available()];
        in.read(Byte_file);



        String encodedString = "{encodedString : "+"data:image/png;base64,"+new String(Byte_file)+"}";

        //sending the String  to the  other client via his session
        socket.session.getAsyncRemote().sendText(encodedString);

    }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!