mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
uploading file works for first time users
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
2081a501a4
commit
c0376c8eed
@ -41,7 +41,8 @@ class FileUploader(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
private var okHttpClientNoRedirects: OkHttpClient? = null
|
private var okHttpClientNoRedirects: OkHttpClient? = null
|
||||||
private var uploadFileUri:String = ""
|
private var okhttpClient:OkHttpClient = okHttpClient
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
initHttpClient(okHttpClient, currentUser)
|
initHttpClient(okHttpClient, currentUser)
|
||||||
@ -54,39 +55,40 @@ class FileUploader(
|
|||||||
createRequestBody(sourceFileUri)
|
createRequestBody(sourceFileUri)
|
||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread()).map { response ->
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.flatMap { response ->
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
ShareOperationWorker.shareFile(
|
ShareOperationWorker.shareFile(roomToken, currentUser, remotePath, metaData)
|
||||||
roomToken,
|
|
||||||
currentUser,
|
|
||||||
remotePath,
|
|
||||||
metaData
|
|
||||||
)
|
|
||||||
FileUtils.copyFileToCache(context, sourceFileUri, fileName)
|
FileUtils.copyFileToCache(context, sourceFileUri, fileName)
|
||||||
true
|
Observable.just(true)
|
||||||
} else {
|
} else {
|
||||||
if (response.code() == 404 || response.code() == 409) {
|
if (response.code() == HTTP_CODE_NOT_FOUND || response.code() == HTTP_CODE_CONFLICT) {
|
||||||
uploadFileUri = ApiUtils.getUrlForFile(
|
createDavResource(sourceFileUri, fileName, remotePath, metaData)
|
||||||
currentUser.baseUrl!!, currentUser.userId!!,
|
|
||||||
)
|
|
||||||
|
|
||||||
val davResource =
|
|
||||||
DavResource(
|
|
||||||
okHttpClientNoRedirects!!,
|
|
||||||
uploadFileUri.toHttpUrlOrNull()!!
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
createFolder(davResource)
|
|
||||||
val value: Observable<Boolean> = upload(sourceFileUri, remotePath, fileName, metaData)
|
|
||||||
value.blockingFirst()
|
|
||||||
} else {
|
} else {
|
||||||
false
|
Observable.just(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun createDavResource(sourceFileUri: Uri, fileName: String, remotePath: String, metaData: String?): Observable<Boolean> {
|
||||||
|
return Observable.fromCallable {
|
||||||
|
val userFileUploadPath = ApiUtils.userFileUploadPath(currentUser.baseUrl!!, currentUser.userId!!)
|
||||||
|
val userTalkAttachmentsUploadPath = ApiUtils.userTalkAttachmentsUploadPath(currentUser.baseUrl!!, currentUser.userId!!)
|
||||||
|
|
||||||
|
var davResource = DavResource(okHttpClientNoRedirects!!, userFileUploadPath.toHttpUrlOrNull()!!)
|
||||||
|
createFolder(davResource)
|
||||||
|
initHttpClient(okHttpClient = okhttpClient, currentUser)
|
||||||
|
davResource = DavResource(okHttpClientNoRedirects!!, userTalkAttachmentsUploadPath.toHttpUrlOrNull()!!)
|
||||||
|
createFolder(davResource)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.flatMap { upload(sourceFileUri, fileName, remotePath, metaData) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
private fun createRequestBody(sourceFileUri: Uri): RequestBody? {
|
private fun createRequestBody(sourceFileUri: Uri): RequestBody? {
|
||||||
var requestBody: RequestBody? = null
|
var requestBody: RequestBody? = null
|
||||||
@ -146,5 +148,7 @@ class FileUploader(
|
|||||||
companion object {
|
companion object {
|
||||||
private val TAG = FileUploader::class.simpleName
|
private val TAG = FileUploader::class.simpleName
|
||||||
private const val METHOD_NOT_ALLOWED_CODE: Int = 405
|
private const val METHOD_NOT_ALLOWED_CODE: Int = 405
|
||||||
|
private const val HTTP_CODE_NOT_FOUND:Int = 404
|
||||||
|
private const val HTTP_CODE_CONFLICT : Int = 409
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,11 @@ object ApiUtils {
|
|||||||
return "$baseUrl/remote.php/dav/files/$user/$remotePath"
|
return "$baseUrl/remote.php/dav/files/$user/$remotePath"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUrlForFile(baseUrl: String, user: String): String {
|
fun userFileUploadPath(baseUrl: String, user: String): String {
|
||||||
|
return "$baseUrl/remote.php/dav/files/$user"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun userTalkAttachmentsUploadPath(baseUrl: String, user: String): String {
|
||||||
return "$baseUrl/remote.php/dav/files/$user/Talk"
|
return "$baseUrl/remote.php/dav/files/$user/Talk"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user