After you have successfully created an account with Cognito User Pool, we will use that account to upload files to the S3 bucket with Amplify in this section.
Keep both terminals running npx ampx sandbox and npm run dev.
Create a storage folder in the amplify folder, then create the amplify/storage/resource.ts file with the content below to add storage to the application:
import { defineStorage } from '@aws-amplify/backend';
export const storage = defineStorage({
name: 'fcajdmsstore',
access: (allow) => ({
'protected/{entity_id}/*': [
allow.authenticated.to(['read']),
allow.entity('identity').to(['read', 'write', 'delete']),
],
}),
});

name: the friendly name of the storage, used to name the S3 bucket.
protected/{entity_id}/*: the folder that stores the user’s files. When a file is uploaded, {entity_id} is replaced with the user’s Identity ID in the Cognito Identity Pool.
allow.authenticated.to(['read']): every signed-in user can read the files.
allow.entity('identity').to(['read', 'write', 'delete']): only the owner of the folder can write and delete files.
Open the amplify/backend.ts file and add storage to the backend:
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
import { storage } from './storage/resource';
defineBackend({
auth,
storage,
});






You have completed user authentication and file upload to S3 with Amplify. The files are stored in the protected/{Identity ID}/ folder because the storage is declared with the protected/{entity_id}/* path. To learn more about access control, move on to the next section.