0

I'm creating an android app which is uploading files to RESTlet server. I'm using below code.

Representation file = new FileRepresentation(filePath, MediaType.IMAGE_ALL);
FormDataSet form = new FormDataSet();
form.setMultipart(true);
form.getEntries().add(new FormData("file", file));
ClientResource cr = new ClientResource(url);
cr.post(form);

The question is: How can I monitor uploading process?

Ziem
  • 6,579
  • 8
  • 53
  • 86

1 Answers1

0

Use an asynk task to do it.

See here a simple example:

private class UploadFilesTask extends AsyncTask<URL, Integer, Long> {
    protected Long doInBackground(URL... urls) {
        // Your upload code with rest client
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

You can see a more consistent and complete example here

João Marcos
  • 3,872
  • 1
  • 19
  • 14
  • Maybe I wasn't clear. I have to pass progress parameter to publishProgress() method but how can I get this variable from ClientResource object? – Fabian Mizieliński Apr 27 '15 at 21:43
  • you cant. Rest is one direction comunication. You only see the result in the final. You can use a progress dialog without percent. – João Marcos Apr 28 '15 at 09:26