I am downloading media files (mainly images) from Supabase Storage using from.download()
in NodeJS.
How can I save the Blob that is returned as a file on my local hard drive?
I am downloading media files (mainly images) from Supabase Storage using from.download()
in NodeJS.
How can I save the Blob that is returned as a file on my local hard drive?
Create a buffer from the Blob and save that on your hard drive.
A working example:
(Note: If you are not working with NodeJS ESM modules, you must use require
instead of import
)
import fs from 'fs'
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(yourSupaseUrl, yourSupabaseKey)
const fileName = 'some-file.png'
const filePath = 'some-folder/' + fileName
const { data, error } = await supabase.storage
.from('storage-name')
.download(filePath)
const blob = data;
const buffer = Buffer.from( await blob.arrayBuffer() );
await fs.promises.writeFile(fileName, buffer);
Links that helped me:
© 2022 - 2024 — McMap. All rights reserved.