vendredi 25 février 2022

Getting invalid file error when we use mime_types (text/csv)

When i am going to import file(vendor.csv). Then i get invalid file error. The reason is that one record in first column data is C & G which create error if we remove space then its working. why? As you can see here in attached screenshot: screenshort of csv

Here is my code

public function import()
    {
        set_time_limit(0);
        $input = Input::all();
        $validator = Validator::make($input, ['file' => 'required|mime_types:text/csv']);

        if($validator->fails()) {
            return ApiResponse::validation($validator);
        }
}

error:

{
    "error": {
        "status_code": 412,
        "validation": {
            "file": [
                "Invalid file type."
            ]
        },
        "message": "Validation Failed"
    }
}

Uploaded file name is testing.csv File data is :

Header:

Display_Name Address City State Zip Type

Data:

  • C & G sdsd 42gfdf DE MI 226 Other

  • asa 516 DYKE SH MI 315 Other

  • A-1 FA 16601 end Ro MI 466 Other

  • A-1 R 30001 CHU MT MI 443 Other

Request sent through Postman Request send through

If we send data like this type then its working Data:

  • C&G sdsd 42gfdf DE MI 226 Other

  • asa 516 DYKE SH MI 315 Other

  • A-1 FA 16601 end Ro MI 466 Other

  • A-1 R 30001 CHU MT MI 443 Other



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire