aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

AWSS3Provider - error uploading TypeError: Cannot read property 'byteLength' of undefined #7945

Closed trdevendran closed 3 years ago

trdevendran commented 3 years ago

Before opening, please confirm:

Is this a production issue?

JavaScript Framework

React Native

Amplify APIs

Storage

Amplify Categories

storage

Environment information

System: OS: macOS 11.0.1 CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz Memory: 617.88 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 15.10.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.11 - ~/Documents/Workspace/Reactnative/chem-native/node_modules/.bin/npm Browsers: Chrome: 89.0.4389.90 Safari: 14.0.1 npmPackages: @babel/core: ^7.13.1 => 7.13.10 @babel/runtime: ^7.13.7 => 7.13.10 @expo/react-native-action-sheet: ^3.8.0 => 3.9.0 @notifee/react-native: ^1.1.1 => 1.1.2 @ptomasroos/react-native-multi-slider: ^2.2.2 => 2.2.2 @react-native-community/art: ^1.2.0 => 1.2.0 @react-native-community/async-storage: ^1.12.1 => 1.12.1 @react-native-community/checkbox: ^0.5.7 => 0.5.7 @react-native-community/clipboard: ^1.5.1 => 1.5.1 @react-native-community/datetimepicker: ^3.0.9 => 3.2.0 @react-native-community/eslint-config: ^2.0.0 => 2.0.0 @react-native-community/image-editor: ^2.3.0 => 2.3.0 @react-native-community/masked-view: ^0.1.10 => 0.1.10 @react-native-community/netinfo: ^6.0.0 => 6.0.0 @react-native-community/slider: ^3.0.3 => 3.0.3 @react-native-community/toolbar-android: 0.1.0-rc.2 => 0.1.0-rc.2 @react-native-community/viewpager: ^4.2.3 => 4.2.4 @react-native-firebase/app: ^10.8.1 => 10.8.1 @react-native-firebase/auth: ^10.8.1 => 10.8.1 @react-native-firebase/firestore: ^10.8.1 => 10.8.1 @react-native-firebase/messaging: ^10.8.1 => 10.8.1 @react-native-firebase/remote-config: ^10.8.1 => 10.8.1 @react-native-firebase/storage: ^10.8.1 => 10.8.1 @react-navigation/bottom-tabs: ^5.11.8 => 5.11.8 @react-navigation/native: ^5.9.3 => 5.9.3 @react-navigation/stack: ^5.14.3. => 5.14.3 @storybook/react-native: ^5.3.25 => 5.3.25 add: ^2.0.6 => 2.0.6 apisauce: ^1.1.1 => 1.1.2 aws-amplify: ^3.3.23 => 3.3.24 babel-jest: ^26.6.3 => 26.6.3 base-64: ^0.1.0 => 0.1.0 buffer: ^6.0.3 => 6.0.3 compare-versions: ^3.6.0 => 3.6.0 eslint: ^7.20.0 => 7.22.0 expo-asset: ^8.1.7 => 8.2.2 expo-av: ^8.2.1 => 8.7.0 expo-constants: ^9.1.1 => 9.3.5 expo-file-system: ^9.0.1 => 9.3.0 expo-font: ^8.2.1 => 8.4.0 expo-image-manipulator: ^8.2.1 => 8.4.0 expo-image-picker: ^8.3.0 => 8.4.0 expo-location: ^8.2.1 => 8.3.0 expo-media-library: ^11.0.0 => 11.0.0 expo-permissions: ^11.0.0 => 11.0.0 formik: ^2.1.4 => 2.2.6 i: ^0.3.6 => 0.3.6 jest: ^26.6.3 => 26.6.3 lodash: ^4.17.21 => 4.17.21 metro-react-native-babel-preset: ^0.65.1 => 0.65.2 moment: ^2.27.0 => 2.29.1 native-base: ^2.13.12 => 2.15.2 ngeohash: ^0.6.3 => 0.6.3 npm: ^6.14.5 => 6.14.11 prop-types: ^15.7.2 => 15.7.2 react: 17.0.1 => 17.0.1 react-native: 0.63.4 => 0.63.4 react-native-animatable: ^1.3.3 => 1.3.3 react-native-calendars: ^1.300.0 => 1.1254.0 react-native-datepicker: ^1.7.2 => 1.7.2 react-native-device-info: ^6.0.0 => 6.2.1 react-native-dotenv: ^0.2.0 => 0.2.0 react-native-easy-grid: ^0.2.2 => 0.2.2 react-native-fbsdk: ^2.0.0 => 2.0.0 react-native-fs: ^2.16.6 => 2.16.6 react-native-geocoding: ^0.4.0 => 0.4.0 react-native-gesture-handler: ^1.6.1 => 1.10.3 react-native-gifted-chat: ^0.16.3 => 0.16.3 react-native-keyboard-aware-scroll-view: ^0.9.3 => 0.9.3 react-native-maps: ^0.27.1 => 0.27.1 react-native-mixpanel: ^1.2.0 => 1.2.5 react-native-modal: ^11.5.6 => 11.7.0 react-native-permissions: ^2.1.5 => 2.2.2 react-native-progress: ^4.1.2 => 4.1.2 react-native-reanimated: ^1.9.0 => 1.13.2 react-native-safe-area-context: ^0.7.3 => 0.7.3 react-native-screens: ^2.9.0 => 2.18.1 react-native-snap-carousel: ^3.9.1 => 3.9.1 react-native-splash-screen: ^3.2.0 => 3.2.0 react-native-svg: ^12.1.0 => 12.1.0 react-native-swiper: ^1.6.0 => 1.6.0 react-native-unimodules: ^0.12.0 => 0.12.0 react-native-vector-icons: ^6.6.0 => 6.7.0 react-native-view-overflow: ^0.0.5 => 0.0.5 react-test-renderer: 17.0.1 => 17.0.1 yup: ^0.29.1 => 0.29.3 npmGlobalPackages: @aws-amplify/cli: 4.45.2 amplify-category-video: 3.3.0 npm: 7.6.3 react-native-cli: 2.0.1 yarn: 1.22.10

Describe the bug

await Storage.put('test.txt', 'Hello') I'm getting the below error while compiling the above line, AWSS3Provider - error uploading TypeError: Cannot read property 'byteLength' of undefined at isEmptyData (VM4 index.bundle:252708) at Sha256.update (VM4 index.bundle:252649) at hmac (VM4 index.bundle:257392) at getSigningKey$ (VM4 index.bundle:257327) at tryCatch (VM4 index.bundle:1485) at Generator.invoke [as _invoke] (VM4 index.bundle:1658) at Generator.next (VM4 index.bundle:1528) at tryCatch (VM4 index.bundle:1485) at invoke (VM4 index.bundle:1558) at VM4 index.bundle:1588

Expected behavior

File upload has to be done with Storage.put() function

Reproduction steps

1.Configure Storage with amplify cli

  1. await Storage.put('test.txt', 'Hello')
  2. You can see the error on console log with the help of catch block

Code Snippet

// Put your code below this line.

Log output

No response

aws-exports.js

No response

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

Note: My objective is to connect an exist bucket by importing storage via amplify cli with below command

amplify import storage

but I have also tried to upload on newly created bucket by using

amplify add storage

await Storage.put('test.txt', 'Hello') I'm getting the below error while compiling the above line,

AWSS3Provider - error uploading TypeError: Cannot read property 'byteLength' of undefined at isEmptyData (VM4 index.bundle:252708) at Sha256.update (VM4 index.bundle:252649) at hmac (VM4 index.bundle:257392) at getSigningKey$ (VM4 index.bundle:257327) at tryCatch (VM4 index.bundle:1485) at Generator.invoke [as _invoke] (VM4 index.bundle:1658) at Generator.next (VM4 index.bundle:1528) at tryCatch (VM4 index.bundle:1485) at invoke (VM4 index.bundle:1558) at VM4 index.bundle:1588

I was trying to upload the video by using the Storage module but faced above error so I'm just trying to upload a text file for the testing purpose but that is also not getting worked: Here are the screenshots with the code snippet and debug points with aws-amplify module,

Screenshot 2021-03-16 at 12 33 46 PM Screenshot 2021-03-16 at 12 31 56 PM

I have clearly understand about the exception because it's accessing an undefined variable but I'm not sure why it's being undefined or why it is not handled to check the undefined value before accessing it:

Screenshot 2021-03-16 at 12 32 21 PM
fminetto commented 3 years ago

I just downgraded the module to 3.3.16 and added a CORS policy to bucket and solved it.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server amplify-help forum.