23 lines
533 B
JavaScript
23 lines
533 B
JavaScript
const { createClient } = require("@supabase/supabase-js")
|
|
|
|
const supabase = createClient(
|
|
process.env.SUPABASE_URL,
|
|
process.env.SUPABASE_KEY
|
|
)
|
|
|
|
async function uploadImage({ bucket, path, fileBuffer, contentType }) {
|
|
const { error } = await supabase.storage
|
|
.from(bucket)
|
|
.upload(path, fileBuffer, {
|
|
contentType,
|
|
upsert: true,
|
|
})
|
|
|
|
if (error) throw new Error(error.message)
|
|
|
|
const { data } = supabase.storage.from(bucket).getPublicUrl(path)
|
|
return data.publicUrl
|
|
}
|
|
|
|
module.exports = { uploadImage }
|