Importing TSV tab delimited content using Filament Import Action

Hello, I'm trying to allow the importing of tab-delimited content in a TSV file using the ImportAction in a getHeaderActions function. Here's my code:
protected function getHeaderActions(): array
{
$fileImports = ImportAction::make('import_data')
->importer(StudentImporter::class)
->csvDelimiter("\t")
->fileRules([
File::types(['csv', 'tsv', 'txt'])->max(1024),
]);

return [
$fileImports,
Action::make('import_device_returns'),
];
}
protected function getHeaderActions(): array
{
$fileImports = ImportAction::make('import_data')
->importer(StudentImporter::class)
->csvDelimiter("\t")
->fileRules([
File::types(['csv', 'tsv', 'txt'])->max(1024),
]);

return [
$fileImports,
Action::make('import_device_returns'),
];
}
I'm running into two issues. First, it's rejecting files with a tsv extension. It returns the error "Expects text/csv, text/x-csv, application/csv, application/x-csv, text/comma-separated-values, text/x-comma-separated-values, text/plain or application/vnd.ms-excel". Second, if I upload a txt file, it's ignoring the \t csvDelimiter option, it sees the header row as 1 long entry. I feel like I may be missing something obvious, but I've searched (Stackoverflow/Github) for importing TSV files and haven't been able to find anything. Any help is appreciated.
No description
No description
2 Replies
toeknee
toeknee4w ago
Can you provide a sample of your tsv?
theweirdone
theweirdoneOP4w ago
Here's a sample of the tsv data:
Grade PSID StudentNumber Email FirstName LastName StudentStatus StudentStatusDate ArrivalDate HomeRoom
"8" "1234" "4321" "[email protected]" "Fname1" "Lname1" "16" "" "08/26/2021" "Homeroom Info1"
"6" "2345" "5432" "[email protected]" "Fname2" "Lname2" "16" "" "08/26/2021" "Homeroom Info2"
"1" "3456" "6543" "[email protected]" "Fname3" "Lname3" "16" "" "08/29/2019" "Homeroom Info3"
"8" "4567" "7654" "[email protected]" "Fname4" "Lname4" "16" "" "08/29/2019" "Homeroom Info4"
Grade PSID StudentNumber Email FirstName LastName StudentStatus StudentStatusDate ArrivalDate HomeRoom
"8" "1234" "4321" "[email protected]" "Fname1" "Lname1" "16" "" "08/26/2021" "Homeroom Info1"
"6" "2345" "5432" "[email protected]" "Fname2" "Lname2" "16" "" "08/26/2021" "Homeroom Info2"
"1" "3456" "6543" "[email protected]" "Fname3" "Lname3" "16" "" "08/29/2019" "Homeroom Info3"
"8" "4567" "7654" "[email protected]" "Fname4" "Lname4" "16" "" "08/29/2019" "Homeroom Info4"

Did you find this page helpful?