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

MD5 not calculating correctly when selecting file from broswer, failing with BadDigest Error #13434

Closed
3 tasks done
sushpatg opened this issue May 27, 2024 · 5 comments
Closed
3 tasks done
Assignees
Labels
bug Something isn't working Storage Related to Storage components/category

Comments

@sushpatg
Copy link

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Storage

Amplify Version

v6

Amplify Categories

storage

Backend

Amplify CLI

Environment information

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 86.14 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/opt/node@20/bin/npm
  Browsers:
    Chrome: 125.0.6422.112
    Safari: 17.4.1
  npmPackages:
    @aws-amplify/ui-react: ^6.1.12 => 6.1.12 
    @aws-amplify/ui-react-internal:  undefined ()
    @smithy/md5-js: ^3.0.0 => 3.0.0 
    @testing-library/jest-dom: ^5.17.0 => 5.17.0 
    @testing-library/react: ^13.4.0 => 13.4.0 
    @testing-library/user-event: ^13.5.0 => 13.5.0 
    aws-amplify: ^6.3.4 => 6.3.4 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    aws-sdk: ^2.1621.0 => 2.1624.0 
    crypto: ^1.0.1 => 1.0.1 
    fs: ^0.0.1-security => 0.0.1-security 
    react: ^18.2.0 => 18.3.1 
    react-dom: ^18.2.0 => 18.3.1 
    react-scripts: 5.0.1 => 5.0.1 
    web-vitals: ^2.1.4 => 2.1.4 
  npmGlobalPackages:
    @amzn/harmony-cli: 1.7.149
    @aws-amplify/cli: 11.1.1
    @aws-amplify/storage: 6.4.2
    corepack: 0.23.0
    n: 9.2.1
    next: 14.1.4
    npm: 10.2.4
    ts-node: 10.9.2
    typescript: 5.5.0-dev.20240526


Describe the bug

Currently when we enable "isObjectLockEnabled" to true. Amplify Library auto-calculates MD5 header: Code Reference

However, this calculation is only working when passing String data. When we select file using the following documented code it throws BadDigest error.

import { uploadData } from 'aws-amplify/storage';

const uploadDataInBrowser = async (event) => {
  if (event?.target?.files) {
    const file = event.target.files[0];
    uploadData({
      path: file.name,
      data: file
    });
  }
};

On debugging the MD5 implementation, could observe that reader.readAsDataURL(blob) returns base64 string and we are encoding it with utf-8 which is causing the error,

Expected behavior

Amplify Library should auto-calculate ContentMD5 value automatically for all types of files selected

Reproduction steps

  1. amplify init
  2. amplify add storage, amplify add auth
  3. amplify push
  4. Use the following code to upload to S3 bucket
import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig, {
  Storage: {
    S3: {
      isObjectLockEnabled: true //OPTIONAl - Object Lock parameter
    }
  }
});

uploadData call

import { uploadData } from 'aws-amplify/storage';

const uploadDataInBrowser = async (event) => {
  if (event?.target?.files) {
    const file = event.target.files[0];
    uploadData({
      path: file.name,
      data: file
    });
  }
};

Code Snippet

import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig, {
  Storage: {
    S3: {
      isObjectLockEnabled: true //OPTIONAl - Object Lock parameter
    }
  }
});

import { uploadData } from 'aws-amplify/storage';

const uploadDataInBrowser = async (event) => {
  if (event?.target?.files) {
    const file = event.target.files[0];
    uploadData({
      path: file.name,
      data: file
    });
  }
};

Log output

// Put your logs below this line


aws-exports.js

{
"aws_project_region": "us-east-1",
"aws_cognito_identity_pool_id": "xxxxxxxx",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "xxxxxxxx,
"aws_user_pools_web_client_id": "xxxxxxxx",
"oauth": {},
"aws_cognito_username_attributes": [],
"aws_cognito_social_providers": [],
"aws_cognito_signup_attributes": [
"EMAIL"
],
"aws_cognito_mfa_configuration": "OFF",
"aws_cognito_mfa_types": [
"SMS"
],
"aws_cognito_password_protection_settings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"aws_cognito_verification_mechanisms": [
"EMAIL"
],
"aws_dynamodb_all_tables_region": "us-east-1",
"aws_dynamodb_table_schemas": [
{
"tableName": "dynamo2f297001-dev",
"region": "us-east-1"
}
],
"aws_user_files_s3_bucket": "fxxxxxxxx",
"aws_user_files_s3_bucket_region": "us-east-1",
"aws_appsync_graphqlEndpoint": "xxxxxxxx",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "xxxxxxxx"
}

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@sushpatg sushpatg added the pending-triage Issue is pending triage label May 27, 2024
@cwomack cwomack added the Storage Related to Storage components/category label May 28, 2024
@cwomack cwomack self-assigned this May 28, 2024
@cwomack
Copy link
Member

cwomack commented May 29, 2024

@sushpatg, thank you for opening this issue and the associated PR #13433! We'll review both internally and follow up with any further questions/suggestions we have.

@cwomack cwomack added bug Something isn't working and removed pending-triage Issue is pending triage labels May 29, 2024
@cwomack
Copy link
Member

cwomack commented May 29, 2024

@sushpatg, marking this as a bug as we investigate it further.

@cshfang
Copy link
Member

cshfang commented Jun 5, 2024

Hi @sushpatg - this fix should be released now with Amplify 6.3.5. Could you please confirm if it is working for you? Thanks

@cshfang
Copy link
Member

cshfang commented Jun 11, 2024

Closing this issue due to inactivity as the bug should be fixed. Please feel free to reopen if the issue persists, thank you!

@cshfang cshfang closed this as completed Jun 11, 2024
@sushpatg
Copy link
Author

Closing this issue due to inactivity as the bug should be fixed. Please feel free to reopen if the issue persists, thank you!

Thank you @cshfang , I was able to test with new version and not facing the issue.

Thank you once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Storage Related to Storage components/category
Projects
None yet
Development

No branches or pull requests

3 participants