1

I have an input for uploading the image in my project that I have implemented with reactjs.

So far, there is no problem, but after uploading the photo, when the user refreshes the page, the photo will be deleted.

How can I prevent the photo from being deleted when the page is refreshed?

Edited:

The file upload component gives me an object that I save as a blob in the state to render. And I also save the same object in the state to send it to the server

<Stack sx={Styles.CameraAndGallaryBox}>
  <input
    accept="image/*"
    style={{ display: "none" }}
    id="raised-button-file"
    type="file"
    onChange={saveImageHandler}
  />
  <label htmlFor="raised-button-file">
    <Button variant="raised" component="span" sx={Styles.button}>
      <Gallary />
      <FormattedMessage id="gallary" />
    </Button>
  </label>
</Stack>

const saveImageHandler = (e) => {
  history.push("/meta-search/image/visual-search");
  dispatch(setImageBlobUrl(URL.createObjectURL(e.target.files[0]))); // for rendering
  dispatch(setImageFile(e.target.files[0])); // to send to the server
  dispatch(visualImageSearch({page:1})); // call api and send photo to server
};
hossein ketabi
  • 480
  • 7
  • 19

0 Answers0