Skip to content

Implement progress notifications for file uploads. #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jensh
Copy link

@jensh jensh commented Aug 30, 2013

Overwrite AsyncHttpResponseHandler.onProgress to get progress
notifications. The implementation forwards a reference to
AsyncHttpResponseHandler to
SimpleMultipartEntity. SimpleMultipartEntity than fires the progress
messages every CHUNKSIZE=65536 bytes in writeTo().

Example usage:

RequestParams params = new RequestParams();
params.put("id", "42");
params.put("remarks", "hello file");
params.put("image",
        new FileInputStream("/path_to_image/123456.jpg"),
        "ImageFilename.jpg",
        "image/jpeg");

final Activity activity = this;
AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(String content) {
                Toast.makeText(activity, "Success: " + content, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onFailure(Throwable error, String content) {
                Toast.makeText(activity, "Failure: " + content, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onProgress(int position, int length) {
                // e.g. Update a ProgressBar:
                progressBarUpload.setMax(length);
                progressBarUpload.setProgress(position);
        }
};

AsyncHttpClient client = new AsyncHttpClient();
client.post("http://192.168.254.1/upload.php", params, responseHandler);

Overwrite AsyncHttpResponseHandler.onProgress to get progress
notifications. The implementation forwards a reference to
AsyncHttpResponseHandler to
SimpleMultipartEntity. SimpleMultipartEntity than fires the progress
messages every CHUNKSIZE=65536 bytes in writeTo().

Example usage:

RequestParams params = new RequestParams();
params.put("id", "42");
params.put("remarks", "hello file");
params.put("image",
        new FileInputStream("/path_to_image/123456.jpg"),
        "ImageFilename.jpg",
        "image/jpeg");

final Activity activity = this;
AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
        @OverRide
        public void onSuccess(String content) {
                Toast.makeText(activity, "Success: " + content, Toast.LENGTH_LONG).show();
        }

        @OverRide
        public void onFailure(Throwable error, String content) {
                Toast.makeText(activity, "Failure: " + content, Toast.LENGTH_LONG).show();
        }

        @OverRide
        public void onProgress(int position, int length) {
                // e.g. Update a ProgressBar:
                progressBarUpload.setMax(length);
                progressBarUpload.setProgress(position);
        }
};

AsyncHttpClient client = new AsyncHttpClient();
client.post("http://192.168.254.1/upload.php", params, responseHandler);
@chug2k chug2k mentioned this pull request Sep 22, 2013
@smarek
Copy link
Member

smarek commented Oct 14, 2013

@jensh this is really nice piece of work, can I ask you to update the pull request against current state of repository master? I've made a lot changes over last few days, and I haven't seen this at first.

@ghost ghost assigned smarek Oct 14, 2013
@smarek
Copy link
Member

smarek commented Oct 14, 2013

Oh, nevermind, I've merged #269 and it cleared out this issue as well.

@smarek smarek closed this Oct 14, 2013
@jensh
Copy link
Author

jensh commented Oct 15, 2013

@smarek, Thank you for merging #269!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants