RESTlet ClientResource with progress bar

134 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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