feat:文件上传支持自定义域名替换
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.nnbc123.core.file.cos
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import com.nnbc123.core.Env
|
||||
import com.tencent.cos.xml.CosXmlService
|
||||
@@ -65,6 +66,7 @@ object CosClient {
|
||||
uploadFile(context, file, outName, token).apply {
|
||||
setCosXmlResultListener(object : CosXmlResultListener {
|
||||
override fun onSuccess(request: CosXmlRequest?, result: CosXmlResult) {
|
||||
transformDomain(result, token)
|
||||
if (Env.isDebug()) {
|
||||
Log.e("CosClient", "upload onSuccess result:${result.accessUrl}")
|
||||
}
|
||||
@@ -87,6 +89,22 @@ object CosClient {
|
||||
}
|
||||
}
|
||||
|
||||
private fun transformDomain(result: CosXmlResult, token: CosToken) {
|
||||
try {
|
||||
if (result.accessUrl.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
if (token.customDomain.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
val newUri = Uri.parse(token.customDomain)
|
||||
result.accessUrl = Uri.parse(result.accessUrl).buildUpon().scheme(newUri.scheme)
|
||||
.authority(newUri.authority).build().toString()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param outName 远端文件名
|
||||
|
@@ -16,6 +16,7 @@ data class CosToken(
|
||||
val region: String?,
|
||||
val startTime: Long?,
|
||||
val expireTime: Long?,
|
||||
val customDomain: String?
|
||||
) {
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user