Skip to content

Instantly share code, notes, and snippets.

@codeagencybe
Forked from pontusab/upload.ts
Created October 28, 2023 09:56
Show Gist options
  • Save codeagencybe/418ffd89e665a3aeea0433ba7c94cd16 to your computer and use it in GitHub Desktop.
Save codeagencybe/418ffd89e665a3aeea0433ba7c94cd16 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