采坑
附上參考鏈接鲫骗,侵權(quán)即刪:https://blog.csdn.net/janronehoo/article/details/88955273
上傳圖片接口NetService.kt中定義為
@Multipart
@POST(UrlDefinition.UPLOAD_IMAGE)
fun uploadImage(@PartMap map: Map<String, RequestBody>): Observable<NetResult<String>>
NetHelper中調(diào)用
fun uploadImage(file: File, length: Int, width: Int, callback: (String) -> Unit, netFinish: (String) -> Unit) {
val partMap = HashMap<String, RequestBody>()
val pic = RequestBody.create(MediaType.parse("multipart/form-data"), file)
partMap["file\";filename=\"" +"file.jpg"] = pic
val lengthBody = RequestBody.create(MediaType.parse("multipart/form-data"),"" + length)
val widthBody = RequestBody.create(MediaType.parse("multipart/form-data"),"" + width)
partMap["length"] = lengthBody
partMap["width"] = widthBody
netApi.uploadImage(partMap)
.asyncSchedulers()
.subscribe(object : BaseSubscribe>() {
override fun onNextData(mData: String) {
callback.invoke(mData)
}
override fun onErrorData(code: Int, msg: String) {
netFinish.invoke(msg)
}
})
}
結(jié)果報(bào)錯(cuò):Parameter type must not include a type variable or wildcard
參照鏈接中說(shuō)加入@JvmSuppressWildcards注解,測(cè)試對(duì)我這邊無(wú)用雄驹,真正原因是定義接口fun uploadImage(@PartMap?map: Map<String, RequestBody>)時(shí)用的是Map??調(diào)用時(shí)傳入的是HashMap<String, RequestBody>()?替久?箱锐?
修改后NetService中上傳接口
fun uploadImage(@PartMap map: HashMap<String, RequestBody>): Observable<NetResult<String>>
再次調(diào)用問(wèn)題已解決。埋同。州叠。
才疏學(xué)淺,記一下采坑凶赁,個(gè)人猜想估計(jì)是Kotlin對(duì)類型要求比較嚴(yán)格咧栗?希望各位大佬留言解釋下逆甜,萬(wàn)分感謝