0

My app uploads an image to the server. In order to execute an uploading, I use the HttpPost class. Here is the relevant code fragment:

try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("%PATH_TO_SERVER_PAGE%");
    
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    httpclient.execute(httppost);
} catch (Exception e) {
    System.out.println("Connection error: " + e.toString());
}

How can I raise an event and know if the uploading has been successfully finished to be sure that the file is already on a server?

Mike
  • 14,010
  • 29
  • 101
  • 161
  • 1
    Once you are done with httpclient.execute that means you are finished uploading, otherwise it goes into the catch section. By the way, it's discouraged to catch Exception, try to narrow it down. – SSC Jul 14 '15 at 20:20
  • Also, create a custom event handler and raise it once you are done with httpclient.execute. – SSC Jul 14 '15 at 20:20

1 Answers1

0

Probably, the implementation of the Observer Design Pattern would be a suitable solution.
Reference: https://stackoverflow.com/a/6270150/462347

Community
  • 1
  • 1
Mike
  • 14,010
  • 29
  • 101
  • 161