mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
create a new folder
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
bb581d0862
commit
ef4d83a691
@ -151,7 +151,7 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
||||
} else {
|
||||
Log.d(TAG, "starting normal upload (not chunked) of $fileName")
|
||||
|
||||
FileUploader(okHttpClient, context, currentUser, roomToken, ncApi)
|
||||
FileUploader(okHttpClient, context, currentUser, roomToken, ncApi, file!!)
|
||||
.upload(sourceFileUri, fileName, remotePath, metaData)
|
||||
.blockingFirst()
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.Response
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
@ -35,11 +36,14 @@ class FileUploader(
|
||||
val context: Context,
|
||||
val currentUser: User,
|
||||
val roomToken: String,
|
||||
val ncApi: NcApi
|
||||
val ncApi: NcApi,
|
||||
val file: File
|
||||
) {
|
||||
|
||||
private var okHttpClientNoRedirects: OkHttpClient? = null
|
||||
private var uploadFolderUri: String = ""
|
||||
private var uploadFileUri:String = ""
|
||||
|
||||
init {
|
||||
initHttpClient(okHttpClient, currentUser)
|
||||
}
|
||||
@ -63,17 +67,21 @@ class FileUploader(
|
||||
true
|
||||
} else {
|
||||
if (response.code() == 404 || response.code() == 409) {
|
||||
uploadFolderUri = ApiUtils.getUrlForFileUpload(
|
||||
uploadFileUri = ApiUtils.getUrlForFile(
|
||||
currentUser.baseUrl!!, currentUser.userId!!,
|
||||
remotePath
|
||||
)
|
||||
|
||||
uploadFolderUri = uploadFileUri + "/" + FileUtils.md5Sum(file)
|
||||
|
||||
val davResource = DavResource(
|
||||
okHttpClientNoRedirects!!,
|
||||
uploadFolderUri.toHttpUrlOrNull()!!
|
||||
|
||||
)
|
||||
|
||||
createFolder(davResource)
|
||||
retryUpload(sourceFileUri, remotePath, fileName, metaData)
|
||||
true
|
||||
val value = retryUpload(sourceFileUri, remotePath, fileName, metaData)
|
||||
value
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -100,9 +108,9 @@ class FileUploader(
|
||||
|
||||
private fun initHttpClient(okHttpClient: OkHttpClient, currentUser: User) {
|
||||
val okHttpClientBuilder: OkHttpClient.Builder = okHttpClient.newBuilder()
|
||||
okHttpClientBuilder.followRedirects(true)
|
||||
okHttpClientBuilder.followSslRedirects(true)
|
||||
okHttpClientBuilder.protocols(listOf(Protocol.HTTP_1_1, Protocol.HTTP_2))
|
||||
okHttpClientBuilder.followRedirects(false)
|
||||
okHttpClientBuilder.followSslRedirects(false)
|
||||
okHttpClientBuilder.protocols(listOf(Protocol.HTTP_1_1))
|
||||
okHttpClientBuilder.authenticator(
|
||||
RestModule.HttpAuthenticator(
|
||||
ApiUtils.getCredentials(
|
||||
@ -137,26 +145,32 @@ class FileUploader(
|
||||
|
||||
private fun retryUpload(
|
||||
sourceFileUri: Uri,
|
||||
uploadUrl: String,
|
||||
remotePath: String,
|
||||
fileName: String,
|
||||
metaData: String?
|
||||
): Observable<Boolean> {
|
||||
return ncApi.uploadFile(
|
||||
ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
||||
uploadUrl,
|
||||
createRequestBody(sourceFileUri)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { retryResponse ->
|
||||
if (retryResponse.isSuccessful) {
|
||||
ShareOperationWorker.shareFile(roomToken, currentUser, uploadUrl, metaData)
|
||||
FileUtils.copyFileToCache(context, sourceFileUri, fileName)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
): Boolean {
|
||||
return try {
|
||||
ncApi.uploadFile(
|
||||
ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
||||
ApiUtils.getUrlForFileUpload(currentUser.baseUrl!!, currentUser.userId!!, remotePath),
|
||||
createRequestBody(sourceFileUri)
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { retryResponse ->
|
||||
if (retryResponse.isSuccessful) {
|
||||
ShareOperationWorker.shareFile(roomToken, currentUser, remotePath, metaData)
|
||||
FileUtils.copyFileToCache(context, sourceFileUri, fileName)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
.blockingFirst()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Retry upload failed", e)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -459,6 +459,10 @@ object ApiUtils {
|
||||
return "$baseUrl/remote.php/dav/files/$user/$remotePath"
|
||||
}
|
||||
|
||||
fun getUrlForFile(baseUrl: String, user: String): String {
|
||||
return "$baseUrl/remote.php/dav/files/$user"
|
||||
}
|
||||
|
||||
fun getUrlForTempAvatar(baseUrl: String): String {
|
||||
return "$baseUrl$OCS_API_VERSION/apps/spreed/temp-user-avatar"
|
||||
}
|
||||
|
@ -90,6 +90,35 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/notification_settings_view"
|
||||
layout="@layout/item_notification_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
<include
|
||||
android:id="@+id/webinar_info_view"
|
||||
layout="@layout/item_webinar_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
<include
|
||||
android:id="@+id/guest_access_view"
|
||||
layout="@layout/item_guest_access_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/conversation_description"
|
||||
android:layout_width="match_parent"
|
||||
@ -139,35 +168,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
android:id="@+id/notification_settings_view"
|
||||
layout="@layout/item_notification_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
<include
|
||||
android:id="@+id/webinar_info_view"
|
||||
layout="@layout/item_webinar_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
<include
|
||||
android:id="@+id/guest_access_view"
|
||||
layout="@layout/item_guest_access_settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/standard_quarter_margin" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/shared_items"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user