简体   繁体   English

读取图像文件并在IE中转换为base64格式

[英]Read image file and convert to base64 format in IE

I am using below jquery which reads the image input from file input and convert into base64 format to display which is working perfectly fine in googlechrome but not in IE. 我正在使用下面的jQuery,它从文件输入中读取图像输入并转换为base64格式以显示,它在googlechrome中工作得很好,但在IE中却没有。 I wanted to acheive the same thing in IE. 我想在IE中达到相同的目的。 Please help 请帮忙

function readImage(input) {
if ( input.files && input.files[0] ) {
    var FR= new FileReader();
    FR.onload = function(e) {
         $('#img').attr( "src", e.target.result );
         $('#base').text( e.target.result );
    };       
    FR.readAsDataURL( input.files[0] );
  }
 }

$("#asd").change(function(){

   readImage( this );
});

IE only supports FileReader in IE10 and higher. IE仅在IE10及更高版本中支持FileReader。

Can I use - FileReader 我可以使用-FileReader

Besides that your IE8 will only support 32kb of data for a base64 image source. 除此之外,您的IE8对于base64图像源仅支持32kb的数据。 You will need to find another approach which involves returning the base64 string explicitly from your server if you are required to support IE9 and lower. 如果需要支持IE9及更低版本,您将需要找到另一种方法,该方法涉及从服务器显式返回base64字符串。 One client side approach would be to extract base64 data from a canvas... 一种客户端方法是从画布中提取base64数据。

how-to-upload-an-image-save-it-to-localstorage-and-then-display-it-on-the-next... 如何将图像保存到本地存储,然后在下一个显示...

Problem with this is IE8 will defeat you again and you will have to go looking for some sort of shim to work around your problem. 问题是IE8会再次打败您,您将不得不寻找某种垫片来解决您的问题。

Can I use - Canvas 我可以使用-帆布
how-can-i-use-the-html5-canvas-element-in-ie 我如何使用html5画布元素

Finally you can try a FileReader polyFill such as 最后,您可以尝试使用FileReader polyFill,例如

https://github.com/Jahdrien/FileReader https://github.com/Jahdrien/FileReader

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

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