I am using Maatwebsite\Excel import in Laravel 5.7 to process an uploaded XLSX file. After this process, I am trying to store the upload file. However, I'm getting following error:
fopen(): Filename cannot be empty at /Users/myuser/workspace/my-application/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:207)
This is my code:
public function import(ImportActivity $request)
{
$params = [
'creator_id' => auth()->user()->id,
'project_id' => $request->project_id,
'overwrite' => $request->has('overwrite')
];
(new ActivitiesImport($params))->import($request->file('excelFile'));
$filename = 'activity_import_' . str_random(16) . '.' . $request->file('excelFile')->getClientOriginalExtension();
$request->file('excelFile')->storeAs('activities', $filename, 'import_files');
return $this->success();
}
Import is being done properly. If I comment the import part, the store is executed perfectly. The error comes from the store process AFTER importing. I also have tested using static calls for import and store with the same result.
Displaying the content of the uploaded file, I have realized that the uploaded file object changes ($request->file('excelFile')):
I don't know the cause of that change in the uploaded file object. In addition, it works if I do it in the opposite order, but I only want to store the file when the import process has been carried out properly.
Can someone help me with my problem, please?
Thanks in advance
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire