Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug (Storage/FileUploader): FileUploader does not upload processed file contents in certain scenarios #6049

Open
4 tasks done
choyky opened this issue Nov 11, 2024 · 3 comments
Labels
bug Something isn't working FileUploader FileUploader related issue of feature request pending-maintainer-response Issue is pending response from an Amplify UI maintainer

Comments

@choyky
Copy link

choyky commented Nov 11, 2024

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Storage

How is your app built?

Vite

What browsers are you seeing the problem on?

Firefox

Which region are you seeing the problem in?

No response

Please describe your bug.

FileUploader does not upload modified file content as described in documentation.

For example, in the following code snippet, file content is replaced entirely but FileUploader still uploads the original input file.

const processFile: FileUploaderProps['processFile'] = async ({ file }) => {
  const fileExtension = file.name.split('.').pop();

  const text = "This is the content of my file";
  const blob = new Blob([text], { type: "text/plain" });
  const processedFile = new File([blob], `${file.name}.txt`, { type: "text/plain" });

  return processedFile
    .arrayBuffer()
    .then((filebuffer) => window.crypto.subtle.digest('SHA-1', filebuffer))
    .then((hashBuffer) => {
      const hashArray = Array.from(new Uint8Array(hashBuffer));
      const hashHex = hashArray
        .map((a) => a.toString(16).padStart(2, '0'))
        .join('');
      return { file: processedFile, key: `${hashHex}.txt` };
    });
};

export function FileUploaderExample() {
  return (
    <FileUploader
      acceptedFileTypes={['image/*']}
      path={({ identityId }) => `private/${identityId}/`}
      maxFileCount={3}
      showThumbnails={true}
      processFile={processFile}
    />
  );
}

If the now deprecated accessLevel is used instead of path as below, then the processed file content will be uploaded as expected.

<FileUploader
      acceptedFileTypes={['image/*']}
      accessLevel='private'
      maxFileCount={3}
      showThumbnails={true}
      processFile={processFile}
    />

What's the expected behaviour?

FileUploader uploads processed/modified file contents instead of the original input.

Help us reproduce the bug!

You could use above example code to reproduce the bug. Check the file contents on S3 and verify that it is the same as original input.

Code Snippet

See above.

Console log output

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify UI maintainer labels Nov 11, 2024
@choyky choyky changed the title FileUploader does not upload processed file contents in certain scenarios Bug (Storage/FileUploader): FileUploader does not upload processed file contents in certain scenarios Nov 11, 2024
@choyky
Copy link
Author

choyky commented Nov 11, 2024

Proposed fix for the issue is submitted here:
#6050

@hbuchel hbuchel removed the pending-triage Issue is pending triage label Nov 11, 2024
@hbuchel
Copy link
Contributor

hbuchel commented Nov 11, 2024

Hi @choyky thanks for filing this bug and for the proposed solution! I was able to replicate your bug in the latest version. I will bring up your PR with the team.

@hbuchel hbuchel added bug Something isn't working FileUploader FileUploader related issue of feature request and removed pending-maintainer-response Issue is pending response from an Amplify UI maintainer labels Nov 11, 2024
@markd-cmn
Copy link

I've found that the suggested workaround using the legacy accessLevel field does indeed allow the modified File object to be uploaded. However, the key is set to the base file name in that case and path cannot be modified via identityId, so it does not completely address the issue.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify UI maintainer label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working FileUploader FileUploader related issue of feature request pending-maintainer-response Issue is pending response from an Amplify UI maintainer
Projects
None yet
Development

No branches or pull requests

3 participants