Files
supabase/apps/studio/lib/upload.ts
Ivan Vasilov 436bdb10ae chore: Move the studio app to apps/studio (#18915)
* Move all studio files from /studio to /apps/studio.

* Move studio specific prettier ignores.

* Fix the ui references from studio.

* Fix the css imports.

* Fix all package.json issues.

* Fix the prettier setup for the studio app.

* Add .turbo folder to prettierignore.

* Fix the github workflows.
2023-11-15 12:38:55 +01:00

46 lines
1.2 KiB
TypeScript

import { createClient } from '@supabase/supabase-js'
const SUPPORT_API_URL = process.env.NEXT_PUBLIC_SUPPORT_API_URL || ''
const SUPPORT_API_KEY = process.env.NEXT_PUBLIC_SUPPORT_ANON_KEY || ''
// [Joshen TODO] Feedback form and support attachments should use this
export const uploadAttachment = async (
bucket: string,
fileName: string,
image: File,
getUrl: boolean = true
) => {
const supabaseClient = createClient(SUPPORT_API_URL, SUPPORT_API_KEY, {
auth: {
persistSession: false,
autoRefreshToken: false,
// @ts-ignore
multiTab: false,
detectSessionInUrl: false,
localStorage: {
getItem: (key: string) => undefined,
setItem: (key: string, value: string) => {},
removeItem: (key: string) => {},
},
},
})
const options = { cacheControl: '3600' }
const { data: file, error } = await supabaseClient.storage
.from(bucket)
.upload(fileName, image, options)
if (error) {
console.error('Failed to upload:', error)
return undefined
}
if (file && getUrl) {
const { data } = await supabaseClient.storage.from(bucket).getPublicUrl(file.path)
return data?.publicUrl
}
return undefined
}