const uploadPage = () => {
const [file, setFile] = useState<File | null>(null);
const handleFileChange = (e:any) => {
setFile(e.target.files[0]);
console.log(file)
};
const handleSubmit = async (e:any) => {
if (file) {
const response = await appwriteFunctions.uploadFile(file);
console.log(response);
}
}
return (
<>
<span className="font-bold text-4xl">Controls</span>
<div className="flex flex-col items-end justify-end gap-4">
<Label htmlFor="picture" className="text-xl">Upload ISO</Label>
<form onSubmit={handleSubmit} className="w-full flex items-end justify-end">
<Input
onChange={handleFileChange}
id="file"
type="file"
ref="file"
value="Reset"
className="w-[19%] border-none h-fit px-5 py-3 text-md outline-dashed outline-1 hover:outline-yellow-100"
/>
<Button type="submit" className="text-white px-4 py-2 rounded">
Upload File
</Button>
{file && <p className="text-sm mt-2">File selected: {file.name}</p>}
</form>
</div>
</>
instead of handleing file change and form submit can this all not be done in the form submission?
i guess i'll try
What error message are you getting?
it just returns null
if you wrap it in a try catch does it throw anything?
nope. I can't even check whether it got the file or not.
its just returning "undefined"
What's returning undefined?
handleFileChange, first step that im doing is making sure its printing on which file was selected
Would you please make sure a file is being passed to setFile
? Then, make sure file is set in handleSubmit
was calling it wrong, managed to fix it π
So the handleSubmit is giving an error. I did follow the docs on how to create a createFile
even tried manually putting my bucket ID instead
What are the permissions on the bucket?
This actually did it, though it wasn't the permission. I was scrolling down and saw the extensions of files had specific set of files to take which prevented it from uploading π
Recommended threads
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- My account is blocked so please check an...
My account is blocked so please unblock my account because all the apps are closed due to which it is causing a lot of problems
- Applying free credits on Github Student ...
So this post is kind of related to my old post where i was charged 15usd by mistake. This happens when you are trying to apply free credits you got from somewh...