Rxphoto: How can i use .requestUri(context, TypeRequest.GALLERY) whit RxJava?
Link ti library: https://android-arsenal.com/details/1/3870#!description
And how then upload this file using Retrofit2? Some examples?
Thanks!
Rxphoto: How can i use .requestUri(context, TypeRequest.GALLERY) whit RxJava?
Link ti library: https://android-arsenal.com/details/1/3870#!description
And how then upload this file using Retrofit2? Some examples?
Thanks!
Use this this
RxPhoto.requestUri(context, TypeRequest.GALLERY)
flatMap(new Func1<Uri, Observable<Response>>() {
@Override
public Observable<Response> call(Uri uri) {
File file = new File(uriString);
RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("upload", file.getName(), reqFile);
RequestBody name = RequestBody.create(MediaType.parse("text/plain"), "upload_test");
return service.postImage(body, name);
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Response>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Response response) {
}
});
The Retrofit call service
interface Service {
@Multipart
@POST("/")
Observable<Response> postImage(@Part MultipartBody.Part image,@Part("name") RequestBody name);
}
Note: Service should be multipart request compulsory in Server Side