答案 0 :(得分:0)
嗯,你可以在发布之前搜索一下,确定你已经找到了一些东西,但是......
@Multipart
@POST(RestClient.UPDATE_USER_PICTURE)
Call<BooleanResponse> updateUserPicture(@Part MultipartBody.Part picture, @Part("picture") RequestBody file);
以上部分是您将使用的改装界面方法
RequestBody reqFile = RequestBody.create(MediaType.parse("multipart/form-data"), loadImageFile);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("picture", loadImageFile.getName(), reqFile);
RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), loadImageFile.getName());
RestClient.getApi().updateUserPicture(filePart, filename).enqueue(new Callback<BooleanResponse>() {
@Override
public void onResponse(Call<BooleanResponse> call, Response<BooleanResponse> response) {
if (response.isSuccessful() && response.code() == 200){
Toast.makeText(CompleteProfile.this, "Picture updated successfully!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<BooleanResponse> call, Throwable t) {
Toast.makeText(CompleteProfile.this, "Request failed !" + t.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "-=onFailure=-\n" + t.getMessage(), t);
}
});