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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:41:08+00:00 2026-06-02T20:41:08+00:00

I am uploading a file to my server using http post i have a

  • 0

I am uploading a file to my server using http post i have a simple method witch gets the job done but the loading…dialog never gets displayed how can i fix this … here is my code

public void send_data() throws IOException
{
    HttpURLConnection connection = null;
    DataOutputStream outputStream = null;
    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary =  "*****";

    ProgressDialog dialog = ProgressDialog.show(CaptureTestActivity.this, "", 
        "Loading. Please wait...", true);
    dialog.show();

    String urlServer = "http://poi.gps.ro:80/postimg?lat=" + String.valueOf(mDraw.lat) + "&lon=" + String.valueOf(mDraw.lon)+"&comment=" + tmp;
    Log.w("DHA", urlServer);
    URL url = new URL(urlServer);
    if (url != null)
    {   
        Log.w("DHA", "Merge aici");
        connection = (HttpURLConnection) url.openConnection();
        if (connection != null)
        {
            Log.w("DHA", "Si aici mere!");
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setUseCaches(false);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Host", "poi.gps.ro");
            connection.setRequestProperty("Connection", "Keep-Alive");
            connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=*****");
            outputStream = new DataOutputStream(connection.getOutputStream());
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + "PICT0000" +"\"" + lineEnd);
            outputStream.writeBytes(lineEnd);
            outputStream.write(btarr.toByteArray());
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
            Log.w("DHA", "Incep trimiterea pozei!");
            outputStream.flush();
            outputStream.close();
            int serverResponseCode = connection.getResponseCode();
            String conn = connection.getResponseMessage();
        //  InputStream in  = connection.getInputStream();
        //  StringWriter writer = new StringWriter();

            Log.w("DHA", conn);
            Log.w("DHA", "Serverul a raspuns cu " + String.valueOf(serverResponseCode));
            if (serverResponseCode == 200)
            {
                AlertDialog alertDialog;
                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle("Super :)");
                alertDialog.setMessage("Poza a fost trimisa cu success.");
                alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {

                      public void onClick(DialogInterface dialog, int id) {

                         finish();

                    } }); 
                alertDialog.show();

            }


}
    }
    dialog.dismiss();
}
  • 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-02T20:41:10+00:00Added an answer on June 2, 2026 at 8:41 pm

    As David said, you need an AsynTask, most practical option. You can do some clever things with the Void, Void, Void part, but unless you want to look into the documentation, this should work fine.

    public class MyActivity extends Activity {
    
    ....
    
        private final class AsyncSender extends AsyncTask<Void, Void, Void> {
    
            ProgressDialog pd;
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
    
                pd = new ProgressDialog(MyActivity.this);
                pd.setTitle("Sending Data");
                pd.setMessage("Please wait, data is sending");
                pd.setCancelable(false);
                pd.setIndeterminate(true);
                pd.show();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                send_data(); // You probably have to try/catch this
                return null;
            }
    
            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                pd.dismiss();
            }
        }
    }
    

    And then when you call it, the cleanest way is to call

    new AsyncSender().execute();
    

    Also, I should mention, this should be an inner class, meaning don’t create a separate java file for it. Generally I just stick them at the bottom of the class file I’m working in.

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

Sidebar

Related Questions

I am trying to upload file on HTTP server using POST but when I
I used this example (http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/) to upload file from android device to server, it
I try to run code from this site http://stunningco.de/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/ but I have a problem,
When uploading files to a web server using HTTP post, are there any restrictions
I am currently looking in to some file uploading using Java Server Faces. I've
I have found numerous examples on uploading a file to a web server via
I am uploading a stream to server.But my Input-stream contain a big video file.So
I have a form which you can post a file over to my server.
I have been using ASIHTTPRequest to do a simple POST upload of a Scores
I have an assignment about uploading and downloading a file to a server. I

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.