Laravel-Excel
Laravel-Excel copied to clipboard
[Bug]: touch(): Unable to create file /app/storage/tmp/laravel-excel/laravel-excel-Lbgb6nfeSe1Hp9kL7ucC2qfZC3jFTNGX.xlsx because No such file or directory
Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?
- [X] Yes, it's still reproducable
What version of Laravel Excel are you using?
3.1.40
What version of Laravel are you using?
9.11.0
What version of PHP are you using?
8.1.7
Describe your issue
This occurs in RemoteTemporaryFile when a local temp directory doesn't exist. For us this is the case a lot of the time as application containers are scaled back and forth, meaning every new container is missing that folder. A newly spawned container might be the one that's processing a ReadChunk job.
[object] (ErrorException(code: 0): touch(): Unable to create file /app/storage/tmp/laravel-excel/laravel-excel-Lbgb6nfeSe1Hp9kL7ucC2qfZC3jFTNGX.xlsx because No such file or directory at /app/vendor/maatwebsite/excel/src/Files/RemoteTemporaryFile.php:97)
[stacktrace]
#0 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /app/vendor/maatwebsite/excel/src/Files/RemoteTemporaryFile.php(97): touch()
#3 /app/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(150): Maatwebsite\\Excel\\Files\\RemoteTemporaryFile->sync()
TemporaryFileFactory has a fix for that, but unfortunately in this case it's never called, because this temporary file comes from deserialization of a job: https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/src/Files/TemporaryFileFactory.php#L49
How can the issue be reproduced?
Not as simple to reproduce, but should be possible.
- Switch to a non-sync QUEUE_DRIVER - for example
redis - Call
Excel::import(new UsersImport, 'users.xlsx');, but don't start the queue worker yet - Go to
storage/framework/cacheand delete thelaravel-exceldirectory. - Run the queue worker.
What should be the expected behaviour?
A temporary files folder should be created prior to calling touch() on a temporary file which might not exist.
Feel free to PR an improvement.
This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.
I ran into a similar issue with vapor and fixed it by changing the config, see below
'local_path' => '/tmp',
'remote_disk' => 's3',
For everyone who bumped into the same issue on vapor. this piece of code did the trick for me: