Upload binary file with retrofit android?

40
April 15, 2019, at 6:00 PM

I have image file to be uploaded to server. The API is to be of Content-Type:application/x-www-form-urlencoded.

Below is my interface method

@Headers("Content-Type: application/octet-stream")
@PUT
Call<UserIdentity> putUserProfileImage(@Url String url,
                                       @Body RequestBody file);

This is my method call

 RequestBody requestBody = RequestBody
            .create(MediaType.parse("application/octet-stream"), profileImage);

    appCMSUserIdentityRest.putUserProfileImage(url, requestBody).enqueue(new Callback<UserIdentity>() {
        @Override
        public void onResponse(@NonNull Call<UserIdentity> call,
                               @NonNull Response<UserIdentity> response) {
            if (response.body() != null) {
                Observable.just(response.body())
                        .onErrorResumeNext(throwable -> Observable.empty())
                        .subscribe(userIdentityAction);
            }else{
                Observable.just((UserIdentity) null)
                        .onErrorResumeNext(throwable -> Observable.empty())
                        .subscribe(userIdentityAction);
            }
        }
        @Override
        public void onFailure(@NonNull Call<UserIdentity> call, @NonNull Throwable t) {
            Observable.just((UserIdentity) null)
                    .onErrorResumeNext(throwable -> Observable.empty())
                    .subscribe(userIdentityAction);
        }
    });
}

I keep getting bad request error.

READ ALSO
How to keep 3rd party library for Android?

How to keep 3rd party library for Android?

I have third party libraries in my projectI added Proguard my project and i make release project but my third party libraries crashes

33
App is getting Restart when data is changed on firebase database [on hold]

App is getting Restart when data is changed on firebase database [on hold]

My app is getting restart when any data is changed in firebase database, even if my app is the onPause mode that time, if changed my database value, app getting restart and show the apphow can i solve it?

20
Extend Gradle Task

Extend Gradle Task

Now in project i am using gradle plugin for hockeyapp

25
How to fix &ldquo;V/FA: Inactivity, disconnecting from the service&rdquo;

How to fix “V/FA: Inactivity, disconnecting from the service”

I'm coding a game to play online throught the firestore serviceIt's a one to one game

41