|
|
@ -185,11 +185,14 @@ class WebDav(urlStr: String) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 上传文件 |
|
|
|
* 上传文件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
suspend fun upload(localPath: String, contentType: String? = null): Boolean { |
|
|
|
suspend fun upload( |
|
|
|
|
|
|
|
localPath: String, |
|
|
|
|
|
|
|
contentType: String = "application/octet-stream" |
|
|
|
|
|
|
|
): Boolean { |
|
|
|
val file = File(localPath) |
|
|
|
val file = File(localPath) |
|
|
|
if (!file.exists()) return false |
|
|
|
if (!file.exists()) return false |
|
|
|
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 |
|
|
|
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 |
|
|
|
val fileBody = file.asRequestBody(contentType?.toMediaType()) |
|
|
|
val fileBody = file.asRequestBody(contentType.toMediaType()) |
|
|
|
val url = httpUrl |
|
|
|
val url = httpUrl |
|
|
|
val auth = HttpAuth.auth |
|
|
|
val auth = HttpAuth.auth |
|
|
|
if (url != null && auth != null) { |
|
|
|
if (url != null && auth != null) { |
|
|
@ -204,9 +207,9 @@ class WebDav(urlStr: String) { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suspend fun upload(byteArray: ByteArray, contentType: String? = null): Boolean { |
|
|
|
suspend fun upload(byteArray: ByteArray, contentType: String): Boolean { |
|
|
|
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 |
|
|
|
// 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 |
|
|
|
val fileBody = byteArray.toRequestBody(contentType?.toMediaType()) |
|
|
|
val fileBody = byteArray.toRequestBody(contentType.toMediaType()) |
|
|
|
val url = httpUrl |
|
|
|
val url = httpUrl |
|
|
|
val auth = HttpAuth.auth |
|
|
|
val auth = HttpAuth.auth |
|
|
|
if (url != null && auth != null) { |
|
|
|
if (url != null && auth != null) { |
|
|
|