简体   繁体   中英

Store an image in browser storage using input type 'file' - Reactjs

I'm trying to store an image in the browser storage when the user selects an image from his/her computer.

<div className="add_grp_image_div margin_bottom">
     <img src={img_upload} className="add_grp_image"/>
     <input type="file" className="filetype"/>
     <span className="small_font to_middle">Add group image</span>
</div>

As shown in the above code i'm opening the file upload window when someone clicks on this div. I want to show the selected image inside the div i have given above. How can i do it?

在此处输入图片说明

My html part looks like this.

You don't need to store the image for showing it to the user or manipulating it.

To show the image, make use of FileReader api. This answer should show you how to display the selected image

To manipulate the image, you need to draw it on a canvas and then perform the selected actions. To draw on the canvas you can follow as described here

But if you wanna to crop it, i suggest you to search for a good javascript image manipulation library. There are n libraries that already does this. It saves time and you can learn much faster without re-inventing the wheel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM