上传二进制文件与改造Android吗?

时间:2019-04-15 08:31:23

标签: android binary retrofit

我有要上传到服务器的图像文件。该API必须为Content-Type:application/x-www-form-urlencoded

下面是我的界面方法

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

这是我的方法调用

 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);
        }
    });
}

我不断收到错误的请求错误。

0 个答案:

没有答案