-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
upload from file in AWS Amplify Gen 2 #13628
Comments
Hey,👋 thanks for raising this! I'm going to transfer this over to our JS repository for better assistance 🙂 |
Hi @ykethan Looking at the error description:
It seemed to be related to GraphQL APIs instead of the Storage |
A small edit, I was actually using a different link to produce this here is my model scheme: //removed todo scheme File_Model: a.model({ also my App.tsx is following the same model from the original starter code that Amplify uses for anyone to build a starter app with the modification of each person having their own data after authentication. //after proper imports const handleChange = (event: any) => { //removed todo functionality code return (
); export default App; |
Hi @Jamalseder7008, this seems like a TS error rather than an Amplify library issue. From the code shared, it seems you have typed the setFile(prev => [...prev, event.target.files[0])]; Also, in the |
Okay, first, thank you for taking the time to try to help me with this. I am still trying to be persistent in solving it, perhaps it is clear but I need a little more help. I've updated my code to reflect exactly what is being shown in the link in the previous message I sent. I've taken your advice, @chrisbonifacio , about the "files" possibly being an array and that might be causing the problem so I've changed it back into the "file" object. The errors that the code is giving me is two different errors, first in line 28: second in line 29: I've uploaded my revised code so that if you'd like to make sure that I'm not making any extra mistakes that could be causing the problem. I've tried using other advice that essentially get rid of the error about file being possibly null but I believe the answer is simpler than some of the solutions I've seen.
|
Hi @Jamalseder7008, the first error is because Here's an edited version of your code to address the errors: import { Authenticator } from "@aws-amplify/ui-react";
import "@aws-amplify/ui-react/styles.css";
import React from "react";
import { uploadData } from "aws-amplify/storage";
function App() {
const [file, setFile] = React.useState<File>();
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (!event.target.files) return; // or handle as an error
setFile(event.target.files[0]);
};
return (
<Authenticator>
{({ signOut, user }) => (
<main>
<h1>{user?.signInDetails?.loginId}'s files</h1>
<div>
<input type="file" onChange={handleChange} />
<button
onClick={() => {
if (!file) return;
uploadData({
path: `picture-submissions/${file.name}`,
data: file,
});
}}
>
Upload
</button>
</div>
<button onClick={signOut}>Sign out</button>
</main>
)}
</Authenticator>
);
}
export default App; After handling the possible undefined state, the overload error also seemed to be resolved. |
Thank you so much for this help, your advice solved the issue that was occurring. All that had to be adjusted was making sure that the code handled the possibility of file being undefined. |
Environment information
Description
Hey while following these steps: https://docs.amplify.aws/react/build-a-backend/storage/upload-files/#upload-from-file
There is an error in this portion:
uploadData({
path:
photos/${file.name}
,data: file,
})
the error is property 'name' does not exist on type '{ name: string; readonly id: string; owner?: string | null | undefined; readonly createdAt: string; readonly updatedAt: string; }[]'.ts(2339)
is there some way to solve this?
The text was updated successfully, but these errors were encountered: