问题描述
当我单击按钮时,callRetrofit
函数开始执行,但是mycall.enqueue
或onFailure
代码块中没有onResponse
个正在执行。我无法从logcat得到任何东西。
这是我的callRetrofit
函数:
private fun callRetrofit() {
val file = File(selectedFile.toString())
val filePrt = RequestBody.create(MediaType.parse("image/*"),file)
val MP2 = MultipartBody.Part.createFormData("Photo","Tasveer",filePrt)
val retrofit = Retrofit.Builder()
.baseUrl("https://www.googleapis.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()
val jsonPlaceholderApi = retrofit.create(Jinterface::class.java)
val mycall = jsonPlaceholderApi.uploadFile(authoo,MP2)
mycall.enqueue(object : Callback<RequestBody?> {
override fun onFailure(call: Call<RequestBody?>,t: Throwable) {
Log.e("dikkat",t.message.toString())
}
override fun onResponse(call: Call<RequestBody?>,response: Response<RequestBody?>) {
Toast.makeText(this@MainActivity,"Donne",Toast.LENGTH_SHORT).show()
textView.text = response.body().toString()
Log.e("ressponse",response.body().toString())
}
})
}
这是界面:
interface Jinterface {
@Multipart
@POST("/upload/drive/v3/files?uploadType=media")
fun uploadFile(
@Header("Authorization") authorization: String,@Part() file: MultipartBody.Part
) : Call<RequestBody>
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)