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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:11:06+00:00 2026-06-14T03:11:06+00:00

i am implementing one app related to send file to server. i am trying

  • 0

i am implementing one app related to send file to server.

i am trying to send file to server by using http post method.

i am getting file from sd card by using the fallowing code.

File root = Environment.getExternalStorageDirectory();
String pathToOurFile = root+"111";

My code is looking like as fallows.

StringBuilder response = new StringBuilder();
try {
  HttpPost post = new HttpPost();
  post.setURI(uri);
  List params = new ArrayList();
  params.add(new BasicNameValuePair("paramName", "paramValue"));
  post.setEntity(new UrlEncodedFormEntity(params));
  DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpResponse httpResponse = httpClient.execute(post);
  if (httpResponse.getStatusLine().getStatusCode() == 200) {
    Log.d(APP_TAG, "HTTP POST succeeded");
    HttpEntity messageEntity = httpResponse.getEntity();
    InputStream is = messageEntity.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(
    openFileInput(pathToOurFile)));
    String line;

    while ((line = br.readLine()) != null) {
     Log.v("info",",,,"+line);
     response.append(line);
     }
   } else {
     Log.e(APP_TAG, "HTTP POST status code is not 200");
   }
} catch (Exception e) {
  Log.e(APP_TAG, e.getMessage());
}

but it is not woking properly .

if know the solution please help me

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-06-14T03:11:07+00:00Added an answer on June 14, 2026 at 3:11 am

    This should work, I havent tested the code though.

     import org.apache.http.HttpEntity;
        import org.apache.http.HttpResponse;
        import org.apache.http.client.HttpClient;
        import org.apache.http.client.methods.HttpPost;
        import org.apache.http.entity.mime.MultipartEntity;
        import org.apache.http.entity.mime.content.FileBody;
        import org.apache.http.entity.mime.content.StringBody;
        import org.apache.http.impl.client.DefaultHttpClient;
    
        ...
    
            public static void uploadFile() throws Exception {
                HttpClient httpclient = new DefaultHttpClient();
                try {
                    HttpPost httppost = new HttpPost(uri);
                    String pathToOurFile = root+"111";
    
                    File f = new File(pathToOurFile);
                    FileBody bin = new FileBody(f);
    
    
                    MultipartEntity reqEntity = new MultipartEntity();
                    reqEntity.addPart("file", bin);
                    reqEntity.addPart("paramName", paramValue);
    
                    httppost.setEntity(reqEntity);
    
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity resEntity = response.getEntity();
    
                    String postResponse = response.getStatusLine();
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am implementing one app related to animation. My require ment is, i have
i am implementing one graph related app. In that when application start i am
I am implementing an app related to SQLite. In that app I created one
I am implementing a web app using angularjs (first time for me). One of
When implementing a hash table using a good hash function (one where the probability
I'm implementing a web app, which uses sessions. I'm using GWT and app engine
I'm looking at implementing an app getting Twitter authorization via Oauth in Java. The
I am implementing an app related to service, my service is running in background
I'm implementing ShareKit in my app; I'm using XCode4 and have downloaded the ShareKit
Implementing Ajax requests in my rails 3 app has been one of the most

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.