Skip to content

Instantly share code, notes, and snippets.

@pontusab
Created October 25, 2023 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pontusab/52dfa9f7efadf6931c672a4f7f55f57a to your computer and use it in GitHub Desktop.
Save pontusab/52dfa9f7efadf6931c672a4f7f55f57a to your computer and use it in GitHub Desktop.
upload.ts
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