Android @Part parameters can only be used with multipart encoding. (parameter #1)

最近使用Retrofit上传头像的时候报错

java.lang.IllegalArgumentException: @Part parameters can only be used with multipart encoding. (parameter #1)
        for method UserService.updateAvatar
        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:755)
        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:746)
        at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:764)
        at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:595)
        at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:339)
        at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:207)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
        at java.lang.reflect.Proxy.invoke(Proxy.java:913)
        at $Proxy3.updateAvatar(Unknown Source)
        at com.chinaso.beautifulchina.net.UserRetrofitManager.updateAvatar(UserRetrofitManager.java:118)
        at com.chinaso.beautifulchina.ui.my.mvp.EditUserPresenterImpl.updateAvatar(EditUserPresenterImpl.java:70)
        at com.chinaso.beautifulchina.ui.my.UserEditActivity.onViewClicked(UserEditActivity.java:175)
        at com.chinaso.beautifulchina.ui.my.UserEditActivity_ViewBinding$3.doClick(UserEditActivity_ViewBinding.java:72)
        at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
        at android.view.View.performClick(View.java:6304)
        at android.view.View$PerformClick.run(View.java:24803)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6604)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)

解决方案

//设置头像
@Multipart    //添加这一行即可
@POST(ConstantUrl.MLZG_BASE_URL + "/usermanager/updateAvatar")
Observable<EditUserResponse> updateAvatar(@Part MultipartBody.Part file);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值