Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
omairaslam817 opened this issue Apr 17, 2020 · 1 comment

Comments

@omairaslam817
Copy link

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

@liesahead
Copy link

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;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants