Skip to content

@aws-amplify/[email protected]

Compare
Choose a tag to compare
@github-actions github-actions released this 12 Jun 16:56
· 7 commits to main since this release
a6bb004

Minor Changes

  • #6575 a004c2f1b9dc74075515a784edb1ee6ce2485602 Thanks @tiffanynwyeung! - feat(storage-browser): add custom file validation and options config

    Add custom file validation

    import React from 'react';
    import { createStorageBrowser } from '@aws-amplify/ui-react-storage/browser';
    import '@aws-amplify/ui-react-storage/styles.css';
    
    const MAX_FILE_SIZE = 1000 * 1000; // 1 MB
    
    const customValidateFile = (file: File) => {
      const isValidSize = file.size <= MAX_FILE_SIZE;
      const isValidType = file.type.includes('image');
      return isValidSize && isValidType;
    };
    
    const { StorageBrowser } = createStorageBrowser({
      // ...config goes here...
      options: {
        validateFile: customValidateFile,
      },
    });
    
    export default function Example() {
      return (
        <StorageBrowser
          displayText={{
            UploadView: {
              getFilesValidationMessage: (data) => {
                const invalidFileNames = data?.invalidFiles?.map(
                  ({ file }) => file.name
                );
                return {
                  content: `Only image files that are 1 MB or smaller are accepted. Invalid files: ${invalidFileNames}`,
                  type: 'error',
                };
              },
            },
          }}
        />
      );
    }

Patch Changes