-
-
Save codeagencybe/418ffd89e665a3aeea0433ba7c94cd16 to your computer and use it in GitHub Desktop.
upload.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SupabaseClient } from "@supabase/auth-helpers-nextjs"; | |
type UploadParams = { | |
file: File; | |
path: string; | |
}; | |
export async function upload( | |
client: SupabaseClient, | |
{ file, path }: UploadParams, | |
) { | |
const bytes = await file.arrayBuffer(); | |
const bucket = client.storage.from(path); | |
const result = await bucket.upload(file.name, bytes, { | |
upsert: true, | |
}); | |
if (!result.error) { | |
return bucket.getPublicUrl(file.name).data.publicUrl; | |
} | |
throw result.error; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment