Back

Need help with STORAGE (no tutorials online)

  • 0
  • Web
  • Storage
  • Cloud
Zip
17 Jun, 2024, 14:04
TypeScript
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>
        </>
TL;DR
Developers were having trouble uploading files due to specific file extensions preventing it. They managed to fix the issue by checking the file extensions. Additionally, they were advised to ensure the file is being passed to `setFile` and to verify that the file is set in `handleSubmit`. The `handleFileChange` function was updated to log the selected file. The unclear error message "undefined" was addressed, suggesting to wrap the code in a try-catch block to capture errors. They were also advised to check if the form submission could handle the file upload process entirely.
Kenny
17 Jun, 2024, 14:14

instead of handleing file change and form submit can this all not be done in the form submission?

Zip
17 Jun, 2024, 14:17

i guess i'll try

Kenny
17 Jun, 2024, 14:18

What error message are you getting?

Zip
17 Jun, 2024, 14:18

it just returns null

Kenny
17 Jun, 2024, 14:20

if you wrap it in a try catch does it throw anything?

Zip
17 Jun, 2024, 14:23

nope. I can't even check whether it got the file or not.

Zip
17 Jun, 2024, 14:23

its just returning "undefined"

Steven
17 Jun, 2024, 14:30

What's returning undefined?

Zip
17 Jun, 2024, 14:30

handleFileChange, first step that im doing is making sure its printing on which file was selected

Steven
17 Jun, 2024, 14:32

Would you please make sure a file is being passed to setFile? Then, make sure file is set in handleSubmit

Zip
17 Jun, 2024, 14:46

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

Zip
17 Jun, 2024, 14:48

even tried manually putting my bucket ID instead

Steven
17 Jun, 2024, 14:51

What are the permissions on the bucket?

Zip
17 Jun, 2024, 14:53

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 πŸ™

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more