angular-cropperjs icon indicating copy to clipboard operation
angular-cropperjs copied to clipboard

cropper js not working for edge browser ,canvas.toBlob() is not function

Open omairaslam817 opened this issue 5 years ago • 1 comments

why canvas.toBlob() is unfriend for edge browser ,kindly share a possible solution for edge browser

omairaslam817 avatar Apr 17 '20 12:04 omairaslam817

Use toDataUrl() instead and then

/**
 * Converts base 64 to File object
 *
 * @param base64String Image in base 64 string format
 * @param name filename
 */
export const dataURLtoFile = (base64String: string, name: string, type: string): File => {
    const parts = base64String.split(',');
    const byteString = atob(parts[1]);
    const intArray = new Uint8Array(byteString.length);

    // Set the bytes of the buffer to the correct values
    for (let i = 0; i < byteString.length; i++) {
        intArray[i] = byteString.charCodeAt(i);
    }

    // IE does not support File() constructor, so we need to create blob.
    // But blob differs from file only because it does not have lastModified and name, which can be added manually
    const file = new Blob([intArray], { type });
    file['name'] = name;
    file['lastModified'] = Date.now();

    return file as File;
};

liesahead avatar Feb 26 '21 13:02 liesahead