1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Validate CSV with different delimiters in Laravel, fileinfo

Discussão em 'Outras Linguagens' iniciado por IGP, Outubro 3, 2024 às 15:03.

  1. IGP

    IGP Guest

    Intro


    I've got two files and I'm trying to post them to an endpoint via cURL.

    file1.csv

    header1,header2
    row1_value1,row1_value2
    row2_value1,row2_value2


    file2.csv

    header1;header2
    row1_value1;row1_value2
    row2_value1;row2_value2


    Only file1.csv passes the validation rule mimes:csv.

    curl -F "file=@file1.csv" -X POST http://host/api/endpoint


    I've tracked down the method that causes the validation to fail. It's in Symfony's FileinfoMimeTypeGuesser which in turn just does

    (new \finfo(\FILEINFO_MIME_TYPE, null))->file($path)

    The question:


    Is it possible to make finfo consider csv's delimited by a non-standard character, such as a semicolon ;, to be considered as a csv file so both of my example files pass Laravel's 'mimes:csv' validation?

    I'm unfamiliar with how finfo works under the hood, but there is an optional $magic_database argument that can be passed in.

    Continue reading...

Compartilhe esta Página