خرید بک لینک

Vote count: 0

I'm trying to get the content of an image in a base64 string.

Originally I was doing it with readAsDataURL but because I want to validate the mimetype on the client side, it seems I have to use readAsArrayBuffer as also pointed out on this site.

So prevoiusly I had this working fine:

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

reader.readAsDataURL(event.target.files[0]);

Reproduction online

Now I added the mimetype validation and I have the following:

var reader = new FileReader();

reader.onloadend = function(event) {

    var realMimeType = getRealMimeType(reader);

    if (realMimeType !== 'unknown') {
        var emptyBufferArray = reader.result; //nothing
    }else{
        alert("Invalid mime type!");
    }
};

reader.readAsArrayBuffer(file);

Reproduction online (not getting the base64 string)

asked 56 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 25 فروردين 1395 ساعت: 6:21

صفحه بندی