Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 959cb7b

Browse files
committed
Retrieve Etag from successful upload
1 parent b59a4e6 commit 959cb7b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/UploadFileFromFileSystemOperation.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
3939
import timber.log.Timber
4040
import java.io.File
4141
import java.net.URL
42-
import java.util.HashSet
4342
import java.util.concurrent.atomic.AtomicBoolean
4443

4544
/**
@@ -63,6 +62,8 @@ open class UploadFileFromFileSystemOperation(
6362
protected val dataTransferListener: MutableSet<OnDatatransferProgressListener> = HashSet()
6463
protected var fileRequestBody: FileRequestBody? = null
6564

65+
var etag: String = ""
66+
6667
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
6768
var result: RemoteOperationResult<Unit>
6869
try {
@@ -107,6 +108,14 @@ open class UploadFileFromFileSystemOperation(
107108

108109
val status = client.executeHttpMethod(putMethod)
109110
return if (isSuccess(status)) {
111+
etag = WebdavUtils.getEtagFromResponse(putMethod)
112+
// Get rid of extra quotas
113+
etag = etag.replace("\"", "")
114+
if (etag.isEmpty()) {
115+
Timber.e("Could not read eTag from response uploading %s", localPath)
116+
} else {
117+
Timber.d("File uploaded successfully. New etag for file ${fileToUpload.name} is $etag")
118+
}
110119
RemoteOperationResult<Unit>(ResultCode.OK).apply { data = Unit }
111120
} else { // synchronization failed
112121
RemoteOperationResult<Unit>(putMethod)

0 commit comments

Comments
 (0)