How to strip type from Javascript FileReader base64 string? -



How to strip type from Javascript FileReader base64 string? -

i've got next code in javascript:

var reader = new filereader(); reader.onloadend = function () { alert(reader.result); };

this shows me next data:

data:image/png;base64,ivborw0kggoaaaansuheugaaaaiaaaaccaaaaabx3vl4aaaacxbiwxmaaastaaaleweampwyaaaab3rjtuuh3gysdcugsze0aaaaaa5jrefucndjrgjgymaaaaj0ah4sdhviaaaaaelftksuqmcc

the thing want part after comma. tried getting reader.result.value, reader.result.valueof() , other combinations, can't find right 1 base64 string starting after comma. sec thought strip off comma , before that, i'm kind of unsure how that.

would have thought how done? tips welcome!

the next functions accomplish desired result:

var base64result = reader.result.split(',')[1];

this splits string array of strings first item (index 0) containing data:image/png;base64 , sec item (index 1) containing base64 encoded data.

another solution find index of comma , cutting off before , including comma:

var base64result = reader.result.substr(reader.result.indexof(',') + 1);

see jsfiddle.

javascript base64 strip

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -