Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix/studio file upload validation (#6639)

bVNyDUKE4353b900d166
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.ts
index df48b1dab40..ac5a636ebcc 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.constants.ts
@@ -3,9 +3,15 @@ import { SpreadsheetData } from './SpreadsheetImport.types'
export const UPLOAD_FILE_TYPES = [
'text/csv',
'text/tab-separated-values',
+ 'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
+export const UPLOAD_FILE_EXTENSIONS = [
+ 'csv',
+ 'tsv',
+]
+
export const EMPTY_SPREADSHEET_DATA: SpreadsheetData = {
headers: [],
rows: [],
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx
index 1e5a376db4b..65e60548cef 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.tsx
@@ -8,7 +8,7 @@ import SpreadSheetTextInput from './SpreadSheetTextInput'
import SpreadSheetFileUpload from './SpreadSheetFileUpload'
import SpreadsheetPreview from './SpreadsheetPreview'
import { SpreadsheetData } from './SpreadsheetImport.types'
-import { parseSpreadsheet, parseSpreadsheetText } from './SpreadsheetImport.utils'
+import { acceptedFileExtension, parseSpreadsheet, parseSpreadsheetText } from './SpreadsheetImport.utils'
import { UPLOAD_FILE_TYPES, EMPTY_SPREADSHEET_DATA } from './SpreadsheetImport.constants'
interface Props {
@@ -58,7 +58,7 @@ const SpreadsheetImport: FC<Props> = ({
setParseProgress(0)
event.persist()
const [file] = event.target.files || event.dataTransfer.files
- if (!file || !includes(UPLOAD_FILE_TYPES, file?.type)) {
+ if (!file || !includes(UPLOAD_FILE_TYPES, file?.type) || !acceptedFileExtension(file)) {
ui.setNotification({
category: 'info',
message: 'Sorry! We only accept CSV or TSV file types, please upload another file.',
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
index 1a63e9b2790..0c3e0bd8ba3 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/SpreadsheetImport/SpreadsheetImport.utils.ts
@@ -2,6 +2,7 @@ import dayjs from 'dayjs'
import Papa from 'papaparse'
import { has, includes } from 'lodash'
import { tryParseJson } from 'lib/helpers'
+import { UPLOAD_FILE_EXTENSIONS } from './SpreadsheetImport.constants'
const CHUNK_SIZE = 1024 * 1024 * 0.25 // 0.25MB
@@ -155,3 +156,8 @@ export const inferColumnType = (column: string, rows: object[]) => {
return 'text'
}
+
+export const acceptedFileExtension = (file: any) => {
+ const ext = file?.name.split('.').pop().toLowerCase()
+ return UPLOAD_FILE_EXTENSIONS.includes(ext)
+}