F
Filament7mo ago
Zod

Why is my CSV Importer reading my CSV deformatted?

I am importing a CSV and my CSV importer is reading the headings deformatted. Some headings that I need are: Issuer_nr, Authority_nr and Kaart serie nummer. Those are being read as: ÿþI�s�s�u�e�r� �N�r� �A�u�t�h�o�r�i�t�y� �N�r� �K�a�a�r�t� �s�e�r�i�e� �n�u�m�m�e�r� When I open the CSV in a code editor it just normally shows the headings as they should be: Issuer Nr;Authority Nr;Kaart serie nummer; When I export the CSV to CSV with numbers it does read the headings normally in the importer. Any ideas?
7 Replies
toeknee
toeknee7mo ago
The CSV isn't saved as UTF8
Zod
ZodOP7mo ago
Is there anyway to still use CSV's not saved as UTF8? It's an export from a system I can't change anything in.
awcodes
awcodes7mo ago
Look up ‘csv BOM’ I’m sure there’s php packages out there that you can use to normalize the csv file contents before running it through the importer. Even with utf-8 I’ve seen issues like this between files saved out of windows vs Mac.
Zod
ZodOP7mo ago
In what function can I write code on the imported file? Any ideas?
Zod
ZodOP7mo ago
Because rn its not matching the values right. I can't find any function to put the normalizing code in before it hits the columns here.
No description
awcodes
awcodes7mo ago
You might need to extend the ImportAction to tap into the forms FileUpload and modify the afterStateUpdated(). Might be possible with one of the Importer lifecycle hooks too. Not 100% sure of the best place to do it. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#lifecycle-hooks
awcodes
awcodes7mo ago
Ideally though, a validation on the file might be better. If it’s not a supported encoding, then don’t allow them to continue. Again not sure where or how to check that. Haven’t don’t anything with the imports personally.
Want results from more Discord servers?
Add your server