I am using following code to upload multiple images to Twitter and get the media_ids as response:
for (int i = 0; i < list_image_paths.size(); i++) {
Log.i("UPLOAD_CHECKER", "image-> " + list_image_paths.get(i));
//get imagepath and create file
String image_path = list_image_paths.get(i);
File imagefile = new File(image_path);
RequestBody file = RequestBody.create(MediaType.parse("image/*"), imagefile);
//start upload
mediaservice.upload(file, null, null).enqueue(new Callback<Media>() {
@Override
public void success(Result<Media> result) {
//Log.e("UPLOAD_CHECKER", "result ID: " + result.data.mediaId);
// media_ids = result.data.mediaIdString;
String got_media_id = result.data.mediaIdString;
Log.e("UPLOAD_CHECKER", "media_id: " + got_media_id);
}
@Override
public void failure(TwitterException e) {
e.printStackTrace();
Log.e("UPLOAD_CHECKER", "error uploading image: " + e.toString());
}
});
}
Currently I am using
.enqueue
so I guess results are summerized before responding. But how can I start uploading and getting response for every for loop iteration? I saw that I can use .execute method but I could not implement it right…
Thanks!