How to strip type from Javascript FileReader base64 string?

爷,独闯天下 提交于 2019-11-28 06:43:14

The following functions will achieve your desired result:

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

This splits the string into an array of strings with the first item (index 0) containing data:image/png;base64 and the second item (index 1) containing the base64 encoded data.

Another solution is to find the index of the comma and then simply cut off everything before and including the comma:

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

See JSFiddle.

let reader: FileReader = new FileReader();

 reader.onloadend = (e) => {
    let base64String = reader.result.split(',').pop();
 };

or

let base64String = /,(.+)/.exec(reader.result)[1];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!