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 6965021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:59:57+00:00 2026-05-27T15:59:57+00:00

I am using MIME multipart for uploading images to server. Sometime image get distorted.

  • 0

I am using MIME multipart for uploading images to server. Sometime image get distorted. How to resolve this issue?
Note: Distorted means, some pixels are lost.
I am using following code for uploading:

File file = new File(filePath[0]);
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost("serverurl");

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("Content-Type",new StringBody("multipart/form-data;charset=utf-8"));
entity.addPart("Content-Length", new StringBody(String.valueOf(file.length())));
entity.addPart("UploadContentPostD", new FileBody(file));                   
entity.addPart("DocumentName", new StringBody(file.getName()));

httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,localContext);
BufferedReader reader = new BufferedReader(new    InputStreamReader(response.getEntity().getContent(), "UTF-8"));

Distorted image is:
enter image description here

  • 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-27T15:59:58+00:00Added an answer on May 27, 2026 at 3:59 pm

    I use Apache Commons for upload and here is my upload code which works perfectly every time…

    public Integer uploadByteArray(String remoteFilename, byte[] bitmapdata){       
            HttpClient client = new HttpClient();
            PostMethod filePost = new PostMethod( URL_PATH);
    
            Integer ret = null;
    
            try {           
                Part[] parts = new Part[2];
                parts[0] = new StringPart("file_name" ,remoteFilename);
    
                ByteArrayPartSource ps = new ByteArrayPartSource("file", bitmapdata);
                parts[1] = new FilePart("file", ps);
    
                filePost.setRequestEntity(new MultipartRequestEntity(parts,
                        filePost.getParams()));
    
            } catch (Exception e) {
                Log.d(TAG, e.toString());
            }
    
            try {
                ret = client.executeMethod(filePost);
                Log.d(TAG, "statusCode>>>" + ret);
                if(ret != 200){
                    Log.d(TAG, "Error:" + ret + " from server. Please try again later.");
                }else{
                    responseBody = filePost.getResponseBodyAsString();
                    Log.d(TAG, filePost.getResponseBodyAsString());
                }
            } catch (Exception e) {
                Log.d(TAG, e.toString());
            }
    
            filePost.releaseConnection();
    
            return ret;
        }
    

    If you continue to see your problem recurring, I would use MD5 on the file you get on the server and send that value back in the response and compare it to a local MD5 of the file you’ve sent up. If they’re not the same, you know something went wrong.

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

Sidebar

Related Questions

Is there a way to get a file's MIME type using some system call
I want to get the MIME type from a filename using C. Is there
I'm trying to get the MIME type of an <input type=file /> element using
I am uploading large files to an ASP.NET server using a standard HTML <input>
From the point of view of uploading, we can use MIME multipart to carry
I'm using perl to assemble a multipart-MIME email, which I'm then sending using sendmail,
I want to send multipart form in my android app but without using org.apache.http.entity.mime
Why webmails (like Gmail) sends MIME messages using multipart/alternative subtype (when composing in HTML)
I have a server sending me this response. However, using the following code I
Objective: I want to send multiple images using multipart/form-data. Below is a snippet of

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.