Upload file/image into server using Coroutine + Retrofit

26 viewsandroidkotlin coroutinesretrofit2
0

I am new coroutines I try to upload file into server (using Retrofit 2.9.0) but I didn’t get the response. Below is my code:

private suspend fun uploadFile(inputFiles: List<String>,channel:Channel<Any>): List<FileResponse>? {
        val partList = buildFilePart(inputFiles)
        QLog.d(TAG,"uploadFile going 1")
        val response = RequestHelper.getUpLoadFilesKotlinRequest().uploadFiles(partList)
        QLog.d(TAG,"uploadFile going 2")
        return response.body()
}
interface UploadFileApiKotlin {
    @Multipart
    @POST("/uploadFile")
    suspend fun uploadFiles(
        @Part listUri: List<MultipartBody.Part>
    ): Response<List<FileResponse>?>
}

After checking logcat, I saw only one line of code:

uploadFile going 1

There is no log line: uploadFile going 2

It seems that coroutine is suspended at line : val response = RequestHelper.getUpLoadFilesKotlinRequest().uploadFiles(partList)

How can I resolve this problem?