diff --git a/src/pages/[platform]/build-a-backend/storage/set-up-storage/index.mdx b/src/pages/[platform]/build-a-backend/storage/set-up-storage/index.mdx index 6f2eccb9fa7..3cc43570f9c 100644 --- a/src/pages/[platform]/build-a-backend/storage/set-up-storage/index.mdx +++ b/src/pages/[platform]/build-a-backend/storage/set-up-storage/index.mdx @@ -790,30 +790,31 @@ class MyApp extends StatefulWidget { Next, let's a photo to the `picture-submissions/` path. -```javascript +```jsx import React from 'react'; import { uploadData } from 'aws-amplify/storage'; function App() { const [file, setFile] = React.useState(); - const handleChange = (event: any) => { - setFile(event.target.files[0]); + const handleChange = (event) => { + setFile(event.target.files?.[0]); + }; + + const handleClick = () => { + if (!file) { + return; + } + uploadData({ + path: `picture-submissions/${file.name}`, + data: file, + }); }; return (
- +
); } diff --git a/src/pages/[platform]/build-a-backend/storage/upload-files/index.mdx b/src/pages/[platform]/build-a-backend/storage/upload-files/index.mdx index 7e34649713f..71248baa3ff 100644 --- a/src/pages/[platform]/build-a-backend/storage/upload-files/index.mdx +++ b/src/pages/[platform]/build-a-backend/storage/upload-files/index.mdx @@ -82,32 +82,33 @@ Learn more about how you can further customize the UI component by referring to The following is an example of how you would upload a file from a file object, this could be retrieved from the local machine or a different source. -```javascript +```jsx import React from 'react'; import { uploadData } from 'aws-amplify/storage'; function App() { - const [file, setFile] = React.useState(); - - const handleChange = (event: any) => { - setFile(event.target.files[0]); - }; - - return ( -
- - -
- ); + const [file, setFile] = React.useState(); + + const handleChange = (event) => { + setFile(event.target.files?.[0]); + }; + + const handleClick = () => { + if (!file) { + return; + } + uploadData({ + path: `photos/${file.name}`, + data: file, + }); + }; + + return ( +
+ + +
+ ); } ```