feat: 增加上传文件接口调用

This commit is contained in:
2023-01-04 09:46:02 +08:00
parent c95096d4fd
commit 7f3560aa5c
6 changed files with 70 additions and 20 deletions

View File

@@ -0,0 +1,7 @@
package com.navinfo.volvo.http
class DefaultResponse<T> {
var code: Int = 0
var message: String = ""
var data: T? = null
}

View File

@@ -1,15 +1,20 @@
package com.navinfo.volvo.http
import com.navinfo.volvo.db.dao.entity.Attachment
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.io.File
class NavinfoVolvoCall {
private val retrofit by lazy {
Retrofit.Builder().baseUrl("http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/")
.addConverterFactory(GsonConverterFactory.create())
.build()
}
companion object {
private val service by lazy {
Retrofit.Builder().baseUrl("http://ec2-52-81-73-5.cn-north-1.compute.amazonaws.com.cn:8088/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(NavinfoVolvoService::class.java)
}
private var instance: NavinfoVolvoCall? = null
get() {
if (field == null) {
@@ -17,7 +22,9 @@ class NavinfoVolvoCall {
}
return field
}
fun getApi(): NavinfoVolvoService {
return service
}
}
}

View File

@@ -1,5 +1,8 @@
package com.navinfo.volvo.http
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.Multipart
import retrofit2.http.POST
@@ -17,7 +20,7 @@ interface NavinfoVolvoService {
fun deleteCardByApp(@Body deleteData: MutableMap<String, String>)
@POST("/img/upload")
@Multipart
fun uploadAttachment(@Part("picture") attachmentFile: File)
suspend fun uploadAttachment(@Part attachmentFile: MultipartBody.Part):DefaultResponse<MutableMap<String, String>>
@POST("/img/download")
fun downLoadAttachment(@Body downloadData: MutableMap<String, String>)
fun downLoadAttachment(@Body downloadData: MutableMap<String, String>):Call<DefaultResponse<MutableMap<String, String>>>
}