Last active
April 28, 2016 14:41
-
-
Save rakesh1988/841f668f49c46ed6e5ce668003d12b17 to your computer and use it in GitHub Desktop.
uploading image to uploads.im
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<ImageUploadResponse> responseArrayList = new ArrayList<>(); | |
// call to upload the image | |
Observable.from(imageStorageList) | |
.flatMap(uri -> new ImageUploadHelper().uploadImage(new File(uri.getPath()))) | |
.toList() | |
.map(list -> { | |
for (ImageUploadResponse response : | |
list | |
) | |
{ | |
if (response.getStatusCode() != 200) // check if all the images were uploaded | |
{ | |
throw new RuntimeException("Unable to upload image"); // this will be thorwn to onError | |
} | |
} | |
request.setPhotoUrls(list); | |
return request; | |
}) | |
.flatMap(user -> apiClient.UpdateUserProfile(/*here your authorization*/, user)) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new Observer<ImageUploadResponse>() | |
{ | |
@Override | |
public void onCompleted() | |
{ | |
} | |
@Override | |
public void onError(Throwable e) | |
{ | |
} | |
@Override | |
public void onNext(ImageUploadResponse imageUploadResponse) | |
{ | |
responseArrayList.add(imageUploadResponse); | |
} | |
}); | |
//once the iamge is uploaded, use the below API to update the information | |
/* | |
@POST("/user/updateProfile") | |
Call<GenericSuccessResponse> UpdateUserProfile(@Header("Authorization") String authorization, | |
@Body User request); | |
User object looks like below | |
public class User | |
{ | |
public String email; | |
public List<ImageUploadResponse> profileImages; | |
//usual getters and setters | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment