amplify-js: Storage.put() throwing [TypeError: undefined is not a function] on React Native
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
Storage
Amplify Categories
auth, storage, api
Environment information
# Put output below this line
System:
OS: Windows 10 10.0.22621
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700K
Memory: 7.25 GB / 31.75 GB
Binaries:
Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 114.0.5735.134
Edge: Spartan (44.22621.1702.0), Chromium (114.0.1823.51)
Internet Explorer: 11.0.22621.1
npmPackages:
@aws-sdk/smithy-client: ^3.306.0 => 3.306.0 (3.186.0, 3.6.1)
@babel/core: ^7.21.8 => 7.21.8 (7.21.3, 7.18.2)
@babel/runtime: ^7.21.5 => 7.21.5 (7.21.0)
HelloWorld: 0.0.1
aws-amplify: ^5.3.0 => 5.3.0
core-js: ^3.30.2 => 3.30.2
date-fns: ^2.29.3 => 2.29.3
react: 18.2.0 => 18.2.0 (17.0.2)
react-native: 0.71.8 => 0.71.8
react-native-reanimated: ~2.14.4 => 2.14.4
reanimated-masonry-list: ^1.0.1 => 1.0.1
ts-jest: ^29.1.0 => 29.1.0
yup: ^1.0.2 => 1.0.2
npmGlobalPackages:
@aws-amplify/cli: 12.0.3
@expo/ngrok: 4.1.0
amplify-cli: 1.0.0
aws-cli: 0.0.2
commitizen: 4.3.0
corepack: 0.10.0
create-expo-app: 1.3.2
create-react-app: 5.0.1
eas-cli: 3.13.2
expo-cli: 6.3.2
lerna: 6.6.1
npm: 8.1.2
sharp-cli: 2.1.0
yarn: 1.22.19
Describe the bug
When trying to call Storage.put() with valid details, an error is thrown [TypeError: undefined is not a function].
Expected behavior
The file is uploaded successfully and no error is thrown.
Reproduction steps
- Select a file to upload
- Call the
Storage.put()API - Notice the call fails
Code Snippet
// Put your code below this line.
public async uploadContent(file, details) {
const fileUri = file.uri;
const fileName = file.name || fileUri.substring(fileUri.lastIndexOf('/') + 1);
const fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);
const generatedContentName = `${uuid.v4()}.${fileExtension}`;
const response = await fetch(fileUri);
const blob = await response.blob();
await Storage.put(generatedContentName, blob, {
level: 'protected',
completeCallback: async () => {
...
},
errorCallback: (err) => {
console.error('Unexpected error while uploading', err);
}
});
}
Log output
// Put your logs below this line
Error uploading file: [TypeError: undefined is not a function]
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
Android Resizeable Emulator
Mobile Operating System
Android 13 (API 33)
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
I have hermes turned on.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (9 by maintainers)
@nadetastic I upgraded to
5.3.3in the app project. That still did not work. When I didyarn list --pattern aws-amplifyI noticed that I had some older version 4 references in the other projects.Since this is a monorepo I wondered if yarn workspaces was being confused. I updated those projects to also have 5.3.3.
I also notice references to
@aws-amplify. Do I need these? I think I was flip-flopping between the two projects during initial setup. The only reference was to@aws-amplify/apiwhen I pulled a type reference from it into my app code. I removed that reference.From the update of the
5.3.3throughout as well as the remove for the@aws-amplifyreference, I was able to successfully upload an image file.EDIT: I would like to add that the initial function I wrote above does work successfully. I do not need to use the
resumable: trueway of upload and can do it in the asynchronous way.I have a slight update. I get this error on Mac (when running on iOS iPhone 14 Pro simulator) instead of running on Windows and Android where I got the initial error:
Error uploading file: [TypeError: _useFipsEndpoint is not a function. (In '_useFipsEndpoint()', '_useFipsEndpoint' is undefined)]