COMMUNITY

JS: Saving a blob object to local your local drive

Thanks to the help of the community, I have a blob object:
var blobObj = new Blob([pixels.bytes.getData()], {type: "image/png"});

What’s the best way to save this png to somewhere on your local computer? FYI, this application would only run on your local machine.

I attempted to use this:

Which saves everything to your downloads folder, which is better than nothing. But it only seemed to work on a text file. Using the png blob example above, it just pumped out a png that says unsupported type when opened.

Thanks!

Not sure what pixels.bytes.getData() is but it’s probably not the bytes of a PNG encoded image.

You might want to use canvas .toBlob method. This will generate a blob of a png encoded image.

Thanks basro.

The pixels variable is from Heaps. Which is hxd.Pixels.

I don’t think I can use canvas.toBlod since I’m getting the data from Heaps?

I’ve never used heaps but It seems hxd.Pixels has a toPNG method, that is probably what you should use.

blob