采坑
附上参考链接,侵权即删: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中调用
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)
}
})
}
结果报错:Parameter type must not include a type variable or wildcard
参照链接中说加入@JvmSuppressWildcards注解,测试对我这边无用,真正原因是定义接口fun uploadImage(@PartMap map: Map<String, RequestBody>)时用的是Map??调用时传入的是HashMap<String, RequestBody>()???
修改后NetService中上传接口
fun uploadImage(@PartMap map: HashMap<String, RequestBody>): Observable<NetResult<String>>
再次调用问题已解决。。。
才疏学浅,记一下采坑,个人猜想估计是Kotlin对类型要求比较严格?希望各位大佬留言解释下,万分感谢
网友评论