upload file to local storage bucket with service key

i cant for the life of me figure out how to upload to storage.

it works fine for authenticated users in the client.
but im trying to do it from a node.js script with the service key.

it seems to be able to download just fine, but can't upload the same file.

if (!URL || !KEY) throw new Error('Missing URL or KEY');

const supabase = createClient(URL, KEY);
const { data, error } = await supabase.storage
    .from('portfolio.quest')
    .download('index.html');
if (error) console.error('download failed, error: '+ error);
else if (!data) console.error('download failed, no data returned');
else console.log('download succeeded: '+ data);

const blob = new Blob(['poop'], { type: 'text/plain' });
const { dataUpload, errorUpload } = await supabase.storage
    .from('portfolio.quest')
    .upload('index.html', blob, {contentType: 'text/plain', upsert: true});

if (errorUpload) console.error('upload failed, error: '+ errorUpload);
else if (!dataUpload) console.error('upload failed, no data returned');
else console.log('upload succeeded: '+ dataUpload);
Was this page helpful?