简体   繁体   中英

Base64 to File Image

I have convert the image file upload to base64 string successfully and it able to display into the img src=""

`var formData = new FormData();
//when we put the value is the upload file it work perfect
//we crop and convert to base64 and display into the img src
formData.append("file", document.getElementById('logo').files[0]);

How to convert the base64 to fileImage so that it can work

也许我误解了这个问题,但这是如何使它显示在页面上。

<img src="data:image/gif;base64,+your_base64_string_here

Use a XMLHttpRequest to send it to your servlet.

                var fd = new FormData();
                fd.append('file', document.getElementById("YourFileInputId").files[0]);
                var req;
                if (window.ActiveXObject) {
                    req=new ActiveXObject();
                } else {
                    req=new XMLHttpRequest();
                }
                req.open("post", "YourServletURLPattern", true);
                req.send(fd);

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