File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
aws-storage-s3/src/main/java/com/amplifyframework/storage/s3
src/main/java/com/amplifyframework/storage Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 15
15
package com.amplifyframework.storage.s3.extensions
16
16
17
17
import com.amplifyframework.storage.StorageException
18
+ import com.amplifyframework.storage.StorageFilePermissionException
18
19
import com.amplifyframework.storage.StoragePathValidationException
19
20
20
21
internal fun StoragePathValidationException.Companion.invalidStoragePathException () = StorageException (
@@ -31,3 +32,12 @@ internal fun StoragePathValidationException.Companion.unsupportedStoragePathExce
31
32
),
32
33
" Provided StoragePath not supported by AWS S3 Storage Plugin"
33
34
)
35
+
36
+ internal fun StorageFilePermissionException.Companion.unableToOverwriteFileException () = StorageException (
37
+ " Unable to overwrite this file for download." ,
38
+ StorageFilePermissionException (
39
+ " Unable to overwrite this file for download." ,
40
+ " Acquire write permission for this file before attempting to overwrite it."
41
+ ),
42
+ " Acquire write permission for this file before attempting to overwrite it."
43
+ )
Original file line number Diff line number Diff line change @@ -24,8 +24,10 @@ import aws.sdk.kotlin.services.s3.model.ObjectCannedAcl
24
24
import com.amplifyframework.core.Amplify
25
25
import com.amplifyframework.core.category.CategoryType
26
26
import com.amplifyframework.storage.ObjectMetadata
27
+ import com.amplifyframework.storage.StorageFilePermissionException
27
28
import com.amplifyframework.storage.s3.AWSS3StoragePlugin
28
29
import com.amplifyframework.storage.s3.TransferOperations
30
+ import com.amplifyframework.storage.s3.extensions.unableToOverwriteFileException
29
31
import com.amplifyframework.storage.s3.transfer.worker.RouterWorker
30
32
import com.amplifyframework.storage.s3.transfer.worker.TransferWorkerFactory
31
33
import java.io.File
@@ -192,6 +194,9 @@ internal class TransferManager(
192
194
val transferRecordId: Int = uri.lastPathSegment?.toInt()
193
195
? : throw IllegalStateException (" Invalid TransferRecord ID ${uri.lastPathSegment} " )
194
196
if (file.isFile) {
197
+ if (! file.canWrite()) {
198
+ throw StorageFilePermissionException .unableToOverwriteFileException()
199
+ }
195
200
logger.warn(" Overwriting existing file: $file " )
196
201
file.delete()
197
202
}
Original file line number Diff line number Diff line change @@ -4212,6 +4212,9 @@ public final class com/amplifyframework/storage/StorageException : com/amplifyfr
4212
4212
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;Ljava/lang/String;)V
4213
4213
}
4214
4214
4215
+ public final class com/amplifyframework/storage/StorageFilePermissionException : com/amplifyframework/AmplifyException {
4216
+ }
4217
+
4215
4218
public final class com/amplifyframework/storage/StorageItem {
4216
4219
public fun <init> (Ljava/lang/String;JLjava/util/Date;Ljava/lang/String;Ljava/lang/Object;)V
4217
4220
public final fun component1 ()Ljava/lang/String;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+ package com.amplifyframework.storage
16
+
17
+ import com.amplifyframework.AmplifyException
18
+ import com.amplifyframework.annotations.InternalAmplifyApi
19
+
20
+ /* *
21
+ * Exception thrown when the necessary file permissions needed to handle a file have not been granted.
22
+ */
23
+ class StorageFilePermissionException @InternalAmplifyApi constructor(
24
+ message : String ,
25
+ recoverySuggestion : String
26
+ ) : AmplifyException(message, recoverySuggestion) {
27
+ @InternalAmplifyApi companion object
28
+ }
You can’t perform that action at this time.
0 commit comments