Created
October 25, 2023 19:49
-
-
Save pontusab/52dfa9f7efadf6931c672a4f7f55f57a 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