Reputation: 51
My website wants to reduce the amount of things users can do with the images...so for added security, we want to keep the image sources as a base64 strings instead of a supabase storage URL. Is this possible through supabase storage, do will I have to save the string in the db?
Upvotes: 2
Views: 3346
Reputation: 195
try this
const base64 = base64image.split('base64,')[1]
const buffer = Buffer.from(base64, 'base64');
const { data, error } = await supabase.storage
.from('avatars')
.upload('avatar.png', buffer, {
contentType: 'image/png', // Adjust based on your image type
});
Upvotes: 0
Reputation: 91
import { decode } from 'base64-arraybuffer'
const image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA='
const base64 = image.split('base64,')[1]
const { data, error } = await supabase
.storage
.from('avatars')
.upload('public/avatar1.png', decode(base64), {
contentType: 'image/png'
})
Upvotes: 8
Reputation: 546
If you want to save your image as base64 you need to save it as a record in your table.
With storage you can create a complex policy and download files from storage and don't share links directly.
Upvotes: 1