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

  • SEARCH
  • Home
  • 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 6009125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:55:34+00:00 2026-05-23T01:55:34+00:00

I am trying to send a photo over http to my server. So i

  • 0

I am trying to send a photo over http to my server. So i convert the image to bytes and then i send it across as a name value pair. Here is my code below for doing so. Now my trouble is the server side, how can i recreate and store the image from the string of bytes recieved

i also am using java servlets

Code on android

ByteArrayOutputStream baos = new ByteArrayOutputStream();
pinnedV.getPhoto().compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();

List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("photo",new String(b)));

HttpClient httpclient = new DefaultHttpClient();  
    HttpPost request = new HttpPost(URL);

    try {
        request.setEntity(new UrlEncodedFormEntity(params));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    ResponseHandler<String> handler = new BasicResponseHandler();  
     try {  
         result = httpclient.execute(request, handler);  
     } catch (ClientProtocolException e) {  
         e.printStackTrace();  
     } catch (IOException e) {  
         e.printStackTrace();  
    }  

Code on server

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

String fromClientphoto= request.getParameter("photo");
byte[] b = fromClientphoto.getBytes();

FileOutputStream fos = new FileOutputStream("D:\\img.png");
     fos.write(b);
     fos.close(); 
}

This above code writes a file but it will not open as an image. also is this byte[] b = fromClientphoto.getBytes(); the correct way to convert back to same bytes as on the android phone? any ideas?

  • 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-23T01:55:35+00:00Added an answer on May 23, 2026 at 1:55 am

    Don’t bother with the toolkit image, just write the contents out to a file..

    can you post an image to the Servlet outside of android? setup a dummy page that does the same thing through a basic HTML Form, break down the problem into smaller and smaller pieces until you figure out whhich piece is causing the problem…

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

Sidebar

Related Questions

Trying to send an array from: <select name='galaddvenn[]' class='sel_add vl hidden' multiple='multiple'> <option value='53'>name1</option>
I am trying to send a proto over a socket, but i am getting
I am trying to send an email from a Ruby program. The smtp server
I am trying to send camera image from one intent to another intent to
Im trying to read in image file from a server , with the code
I am trying to access iPhone's photo album photo images through ALAssetsLibrary and upload(send)
Im trying to send via ajax a value from a textfield, but don't want
I'm trying to send an email using the GMail SMTP server. I have the
Trying to send 3rd party scripts over an SSL or SPDY connection is a
Im trying to send a command through telnet to my computer which then sends

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.