Coder Social home page Coder Social logo

Comments (1)

liesahead avatar liesahead commented on July 22, 2024

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

from angular-cropperjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.