Skip to content

S3. Cannot find the item specified by the provided path  #5601

Open
@Dapucla

Description

@Dapucla

Description

Simply after uploadImage() function gets triggered and you select actually existing image with path. Error appears - "Cannot find the item specified by the provided path"

amplify/storage/resource.ts

import { defineStorage } from '@aws-amplify/backend';

export const storage = defineStorage({
  name: "mediafiles",
  access: (allow) => ({
    "media/public/{entity_id}/": [
      allow.guest.to(["read]"]),
      allow.entity("identity").to(["read", "write", "delete"]),
      allow.groups(["Admins"]).to(["read", "write", "delete"]),
    ],
    "media/protected/{entity_id}/": [
      allow.authenticated.to(["read"]),
      allow.entity("identity").to(["read", "write", "delete"]),
    ],
    "media/private/{entity_id}/*": [
      allow.entity("identity").to(["read", "write", "delete"]),
    ],
  }),
});
amplify/backend.ts

import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { storage } from './storage/resource';
import { myFirstFunction } from './my-first-function/resource';

/**
 * @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
 */
const backend = defineBackend({
  auth,
  data,
  storage,
  myFirstFunction
});


// extract L1 UserPool construct
const { cfnUserPool } = backend.auth.resources.cfnResources;
// from the CDK use `addPropertyOverride` to modify properties directly
cfnUserPool.addPropertyOverride('Policies.PasswordPolicy.RequireUppercase', false);
cfnUserPool.addPropertyOverride('Policies.PasswordPolicy.RequireNumbers', false);
cfnUserPool.addPropertyOverride('Policies.PasswordPolicy.RequireSymbols', false);
Future<void> uploadImage() async {
  // Select a file from the device
  final result = await FilePicker.platform.pickFiles(
    type: FileType.custom,
    withData: false,
    // Ensure to get file stream for better performance
    withReadStream: true,
    allowedExtensions: ['jpg', 'png', 'gif'],
  );

  if (result == null) {
    safePrint('No file selected');
    return;
  }

  // Upload file using the filename
  final platformFile = result.files.single;
  try {
    final result = await Amplify.Storage.uploadFile(
      localFile: AWSFile.fromStream(
        platformFile.readStream!,
        size: platformFile.size,
      ),
      path: StoragePath.fromIdentityId((id) => "media/public/$id/${platformFile.name}"),
      onProgress: (progress) {
        safePrint('Fraction completed: ${progress.fractionCompleted}');
      },
    ).result;
    safePrint('Successfully uploaded file: ${result.uploadedItem.path}');
  } on StorageException catch (e) {
    safePrint(e.message);
  }
}

flutter: -->      Subscription established
flutter: Fraction completed: 0.6744884936807871
flutter: Fraction completed: 1.0
flutter: Fraction completed: 1.0
flutter: Fraction completed: 1.0
flutter: Cannot find the item specified by the provided path.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

Simply trigger uploadImage() function, during which after selecting image terminal states -

flutter: Cannot find the item specified by the provided path.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.24.0

Amplify Flutter Version

2.4.0

Deployment Method

Amplify Gen 2

Schema

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionA question about the Amplify Flutter librariesstorageIssues related to the Storage Category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions