javascript - How to get base64 from input file in IE without using FileReader or HTML5 -
I hope I can help you with a file from an HTML input
file element Need to get.
This is HTML:
& lt; Input type = "file" name = "allegatoImg" id = "allegatoImg" onchange = "javascript: readURL (this)" />
And this is Javascript:
function readURL (input) {var mimeType; If (window.FileReader) {if (input.files and input.files [0]) {var reader = new FileReader (); Reader.loads = function (e) {var dataURL = e.target.result; MimeType = DataURL.split (",") [0] .split (":") [1] .split (";") [0]; If (mime type == 'image / jpeg') {jQuery ('# iggleGlato'). Et ('src', e.target.result); // jQuery ('#fotoTemp'). Attr ('src', e.target.result); ProvaInvioImgSrcToServer (); } And {warnings ('error neela let file. Controller's Sia Stato Carriata un File Constance JPG.'); Return; }}; Reader.readAsDataURL (input.files [0]); }} And {f = document.dettRichAbbForm; Document.getElementById ("imgallegato"). Src = "file: ///" + input.value; Var estensione = ctrlExtensionFileIE (input.value); Warning ('path file =' + jQuery ("# imgallegato"). Attr ('src')); If (Estation == 'JPG' || Estation == 'JPG') {provaInvioImgSrcToServer (); } Else {Warning ('Error reading file'); Return; }}} Function provaInvioImgSrcToServer () {var urlToCall = provaInvioImgSrcToServerUrl; Warning ('img path =' + jQuery ("# iggleletto"). Et ('src')); Atr ('src')}, success: function (jquery.ajax) {RitagliaImg ();}, error: function (error message) {// gestAjaxCallError (error message, divResultBodId, divResultBodId); Warning ('Errore nel caricamento dell' immagine selezionata.))}}}; } Function ctrlExtensionFileIE (value) {var splittedVal = value.split ("."); Return split val [1]; }
I am working on an older version of Liferay 5.1 jQuery , so I do not use HTML5 with the canvas element , Because I should load the image from the input file into the jcrop element.
My problem is linked to this part of the code:
F = document.dettRichAbbForm; Document.getElementById ("imgallegato"). Src = "file: ///" + input.value; Works fine in Mozilla, Chrome and IE10 +, but with IE9- I should use the above code
The problem is that input .value
gives the path of the selected file and to send it to the server I need to get base 64 I do not submit my form Because this approach needs to reload my JSP and I have other fields. Is there anyone who can help me get a byte array from the selected file on IE without using Canvas element, HTML5 and File Reader Library?
Comments
Post a Comment