Get JavaScript Blob Filename Without Link - Quick & Easy

If you are working with JavaScript blobs, you might run into a situation where you need to get the filename of the blob without having a link. Fortunately, this is a quick and easy task that can be accomplished with just a few lines of code.

To get the filename of a JavaScript blob, you can use the name property of the File object. This property is set automatically when the blob is created, so all you need to do is access it.

Here's an example:

const blob = new Blob(['Hello, world!'], {type: 'text/plain'});
const filename = new File([],'test.txt', {type: blob.type}).name;
console.log(filename); // Outputs 'test.txt'

In this example, we create a new blob with the text 'Hello, world!' and a type of 'text/plain'. We then create a new File object with an empty array, a filename of 'test.txt', and the same type as the blob. Finally, we access the name property of the File object to get the filename.

With this technique, you can easily get the filename of a JavaScript blob without having to rely on a link.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information