Giter Club home page Giter Club logo

b64-to-blob's Introduction

b64toBlob(b64Data: string, contentType?: string): Blob converts a base64 string to a Blob object as described in this Stack Overflow post.

Note that the Blob class only exists in browsers, not Node, so this package is only meant for use in the browser and simulated browser environments, not as part of a typical Node server.

Example Usage

This module uses the UMD returnExports pattern to export itself for either AMD or Node/Webpack module loading, falling back to a global browser definition if neither are available.

With Webpack

npm install b64-to-blob
var b64toBlob = require('b64-to-blob');

var contentType = 'image/png';
var b64Data =
    'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' +
    'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHx' +
    'gljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';

var blob = b64toBlob(b64Data, contentType);

var blobUrl = URL.createObjectURL(blob);
window.location = blobUrl;

Without a Build Step

<script src="https://unpkg.com/b64-to-blob"></script>
<script>
    var contentType = 'image/png';
    var b64Data =
        'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' +
        'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHx' +
        'gljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';

    var blob = b64toBlob(b64Data, contentType);

    var blobUrl = URL.createObjectURL(blob);
    window.location = blobUrl;
</script>

b64-to-blob's People

Contributors

jeremybanks avatar

Watchers

 avatar  avatar

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.