react-images-upload
react-images-upload copied to clipboard
can I get image path?
This is so nice uploader and I like it
onChange function didnt return image path but only image name How can I get image path and image name?
Thank you.
same, I also need the image path
Well, I did this in my onDrop function:
const onDrop = (picture) => {
// use the FileReader to decode de picture file that comes
let reader = new FileReader();
let url = reader.readAsDataURL(picture[0]); // for the first picture in this case
reader.onloadend = function (e) {
// the reader.result variable will have your url, in this case I set the pictureUrl state to that
setPictureUrl(reader.result);
};
};
and I can show the image in some preview in the page like this:
<img style={{ height: "50px", width: "50px" }} src={pictureUrl} />
** I have the following hooks, just in case it was not clear:
const [pictureUrl, setPictureUrl] = useState("");