Folks, I’m working on a blog in React, kind of a WordPress clone, I guess, and I want users to be able to upload pictures. Any basic ideas on how to do this?
I’m thinking the form to make a post should have an input form, maybe something like this?
But then how would that be stored in React? I’m thinking the form submission should create an <Image src="{image} alt="image /> thing that will go in the <Post />.
Also, the picture will eventually be stored in the Firebase Real-Time database that the blog is hooked up to. If you want to look at what I have so far, it’s here: deployment
I’m thinking the form submission should take data, put it somewhere, and the presentation layer, e.g. a React component, should render an output from the data.
You should put an onChange function to your file input and then store it in the state.
// say we have [files,setFiles] state
setFiles(e.target.files[0]);
// That is if you want to preview the image to the user.
// [image,setImage] state
setImage(window.URL.createObjectURL(e.target.files[0]));
You can then store that file state in firebase, they have a detailed documentation on this on their storage documentation.