How to strip type from Javascript FileReader base64 string?

后端 未结 3 1984
死守一世寂寞
死守一世寂寞 2020-12-02 16:18

I\'ve got the following code in my Javascript:

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

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 17:02

    You can try splitting your data using ;base64,.

    // In here you are getting the data type. Ex - png, jpg, jpeg, etc. You can use this for any further purposes.
    var dataType = reader.result.split(';base64,')[1];
    
    // In here you are getting the base64 string and you can use this for your purpose.
    var base64result = reader.result.split(';base64,')[1];
    

提交回复
热议问题