5

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?

1 Answer 1

11

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.