简体   繁体   English

Base64到文件映像

[英]Base64 to File Image

I have convert the image file upload to base64 string successfully and it able to display into the img src="" 我已将图像文件上传成功转换为base64字符串,并且能够显示为img src =“”

`var formData = new FormData(); `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 //我们裁剪并转换为base64并显示到img src中
formData.append("file", document.getElementById('logo').files[0]); formData.append(“ file”,document.getElementById('logo')。files [0]);

How to convert the base64 to fileImage so that it can work 如何将base64转换为fileImage,使其可以工作

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

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

Use a XMLHttpRequest to send it to your servlet. 使用XMLHttpRequest将其发送到您的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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