#✅ - Error 403 - StorageError: Access denied!

8 messages · Page 1 of 1 (latest)

hallow iron
#

I am getting StorageErrors for both upload and list.

Error: StorageError: Received HTTP Response status code 403 Forbidden Recovery suggestion: Make sure the user has access to the key before trying to download/upload it.

I created a new iOS test app with Storage accessible to guests. But upload and list are throwing errors.

export const storage = defineStorage({ name: 'ampSampleDrive', access: (allow) => ({ 'test/*': [ allow.guest.to(['read', 'write']), ] }) });

` func upload() async throws {
let dataString = "My Data"
let data = Data(dataString.utf8)

    let uploadTask = Amplify.Storage.uploadData(
        key: "test/\(UUID().uuidString)",
        data: data
    )

    let value = try await uploadTask.value
    print("Completed: \(value)")
}`
plush cape
#

Hi @hallow iron ! You are using the deprecated method that takes the key parameter, which does not work with Gen2.
Instead you should use path :

let uploadTask = Amplify.Storage.uploadData(
    path: .fromString("test/\(UUID().uuidString)"),
    data: data
)

You can read the documentation here.

hallow iron
# plush cape Hi <@712447567606317148> ! You are using the deprecated method that takes the `k...

Thanks a bunch for the help. The upload worked!

I am still unable to get "list" to work.
func list() async throws { let options = StorageListRequest.Options(pageSize: 1000) let listResult = try await Amplify.Storage.list( path: .fromString("test"), options: options ) listResult.items.forEach { item in print("Path: \(item.path)") } }

I am getting
StorageError: Access denied! Caused by: UnknownAWSHTTPServiceError(typeName: Optional("AccessDenied"), message: Optional("Access Denied"), requestID: Optional("B8QDXKPS1YR8D5NT"), requestID2: Optional("8E88JG2UcwexoAB5Mj2YBVMKCbj+Be7XpkoNae6gxgjFgZZAuFSLaI9pcq3evmUKccbmImHsb2ZdP/iptuugEw=="), httpResponse: Status Code: http_status_403

plush cape
#

You need to include the trailing "/" in your path, otherwise you're attempting to list the contents of the root folder (for which you don't have access to).

So it should be path: .fromString("test/")

hallow iron
#

Thank you very very much.
I spent more than a week on this issue. I tried test apps from scratch multiple times.

I wish the example in the Amplify documentation had a trailing slash.
let options = StorageListRequest.Options(pageSize: 1000) let listResult = try await Amplify.Storage.list( path: .fromString("public/example/path"), options: options ) listResult.items.forEach { item in print("Path: \(item.path)") }

plush cape
#

I can see how that's confusing. We will take a note to update the documentation 🙂

plush cape
echo bronzeBOT
#

✅ - Error 403 - StorageError: Access denied!