Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

What is a blob?

I am trying to convert a base64 code into a pdf. The way I have seen on stackoverflow, they said to convert into a blob and then do whatever you want. I do not know what blob is and why we need it to convert a base64 into a file? The data is a object with key value. I tried tgat base64 in a online converter and it gave me a pdf but unable to understand how do I do it?

1 Answer

Steven Parker
Steven Parker
221,297 Points

A "Blob" is an object that represents immutable, raw data, that isn't necessarily in a JavaScript-native format. For more information, see the MDN page.

Once you've decoded the data, you probably want to write it into a disk file. Assuming you're working in node.js, the fs module might be useful for that. The conversion itself might be done using the b64-to-blob package.

It is hard to understand. What if I got a file, say a ready to go PDF and want to download on button click, do I need blob to save file to disk as it is already a file, what steps are involved?

Steven Parker
Steven Parker
221,297 Points

The File interface is based on Blob, so when using it you should not need a separate Blob object.