Since temporary files are automatically deleted after the current script is finished (#50778308), If I dispatch a Laravel Job to process an uploaded file, which is simply temporary file, is there a risk that the file won't be found?
Asked
Active
Viewed 331 times
0
-
1If you need to process this file, store it on your storage folder, then delete it on your job after processing it. – Elias Soares Oct 21 '18 at 16:21
-
Exactly @EliasSoares and you can also safely resize, reformat or watermark it. Don't rely on the queue for this type of job. I have actually unqueued uploading files. Even to S3. The processing, once uploaded, goes so fast, there is no need for a queue. – Dimitri Mostrey Oct 21 '18 at 16:34
1 Answers
1
No, the Job will not be able to access the temporary uploaded file. Jobs are processed by a separate worker process after the request has already finished, which means temp files have already been removed.
As Elias said, the solution is to save the file during the request, and then the job can delete the file when it's done processing.
The exception is when you use the sync
queue driver, which processes jobs immediately when they're dispatched. In this case the job is run during the request, so the job would be able to access the temporary uploaded file.

Travis Britz
- 5,094
- 2
- 20
- 35