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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:28:03+00:00 2026-06-17T12:28:03+00:00

How can i write a simple Android file uploaded using a POST method to

  • 0

How can i write a simple Android file uploaded using a POST method to a PHP server

  • 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-17T12:28:04+00:00Added an answer on June 17, 2026 at 12:28 pm

    Please download HttpComponents and add it to your Android Project. If you want to upload a file with a POST method you have to use Multipart.

      private DefaultHttpClient mHttpClient;
    
    
        public ServerCommunication() {
            HttpParams params = new BasicHttpParams();
            params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            mHttpClient = new DefaultHttpClient(params);
        }
    
    
        public void uploadUserPhoto(File image) {
    
            try {
    
                HttpPost httppost = new HttpPost("some url");
    
                MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
                multipartEntity.addPart("Title", new StringBody("Title"));
                multipartEntity.addPart("Nick", new StringBody("Nick"));
                multipartEntity.addPart("Email", new StringBody("Email"));
                multipartEntity.addPart("Description", new StringBody(Settings.SHARE.TEXT));
                multipartEntity.addPart("Image", new FileBody(image));
                httppost.setEntity(multipartEntity);
    
                mHttpClient.execute(httppost, new PhotoUploadResponseHandler());
    
            } catch (Exception e) {
                Log.e(ServerCommunication.class.getName(), e.getLocalizedMessage(), e);
            }
        }
    
        private class PhotoUploadResponseHandler implements ResponseHandler {
    
            @Override
            public Object handleResponse(HttpResponse response)
                    throws ClientProtocolException, IOException {
    
                HttpEntity r_entity = response.getEntity();
                String responseString = EntityUtils.toString(r_entity);
                Log.d("UPLOAD", responseString);
    
                return null;
            }
    
        }
    

    Source: Post multipart request with Android SDK

    Also read this tutorial for an AsyncTask example. An AsyncTask is a little bit harder to code, but if you don’t use it your app is going to upload files in the main thread. Your application will freeze while uploading a file, if it takes longer then 5 seconds Android will say that your Application is not responding. If you use an AsyncTask for downloading/uploading a file Android creates a new Thread and your application won’t freeze.

    Please note that if you use multiple AsyncTasks Android will execute the AsyncTasks one at the time, you cannot run multiple AsyncTasks at the same time but in the most cases you don’t have to.

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

Sidebar

Related Questions

I am attempting to write a simple game server for an Android game using
I am trying to write header file. I can write simple headers like add(int
Im making a simple programm for android, what can add, read and write text
I tried a simple file write program in Android. try { //File f1=new File(/sdcard/Prag.txt);
how can I write just a simple disassembler for linux from scratches? Are there
how can i write dynamic javascript any simple example or any references. thanking you
I want to write a simple class (PHP5) that can 'run' an unknown amount
My question is pretty simple: How can I write a function once and make
i need to write simple android application that run on the background and read
I am a new android developer trying to write a simple contact book. When

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.