Vous essayez de télécharger une photo de profil via l'appel API à l'aide de Retrofit 2 et de rxjava. La réponse me donne toujours une erreur qui est 422 Entité non traitable. Donner mon code et besoin de suggestion pour surmonter cela.Rénovation 2 Téléchargement de fichiers en plusieurs parties Erreur
@Multipart
@POST("api/update-profile-picture")
Observable<ProfilePicture> updateProfilePicture(
@Header("Authorization") String accessToken,
@Part("profile_picture") RequestBody profile_picture
);
// calling presenter method to update profile picture
public void updateProfilePictureImage(File file){
getMvpView().showProgress();
RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
//MultipartBody.Part body = MultipartBody.Part.createFormData("profile_picture", file.getName(), reqFile);
oyeBuddyService.updateProfilePicture("Bearer" + " " + mPrefs.getOyeUserAccessToken(), reqFile)
.subscribeOn(mNewThread)
.observeOn(mMainThread)
.subscribe(new Observer<ProfilePicture>() {
@Override
public void onCompleted() {
getMvpView().hideProgress();
}
@Override
public void onError(Throwable e) {
getMvpView().hideProgress();
Log.e("error: ",e.getMessage());
}
@Override
public void onNext(ProfilePicture profilePicture) {
Log.e("response: ", profilePicture.toString());
getMvpView().onProfilePictureUpdated(profilePicture.profile_picture_url);
}
});
}
Réponse --->
RetrofitModule: Received response for http://174.138.64.95/api/update-profile-picture in 4540.6ms
Date: Wed, 04 Oct 2017 10:30:53 GMT
Server: Apache/2.4.18 (Ubuntu)
Vary: Authorization
Cache-Control: no-cache, private
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
Content-Length: 99
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/json
E/error:: HTTP 422 Unprocessable Entity
Cela peut aider u https://github.com/square/retrofit/issues/696 – Anil
@Anil merci. Il n'a pas aidé –