How to save a file in local storage

I am trying to upload a file to a temporary location with the Laravel Storage Facade and it says that the file does not exist. I am trying to upload a file to a file. / storage / app / roofing / projects / {id} / then. Not sure where exactly I'm wrong.

foreach ($files as $file) { $path = Storage::putFile('contract-assets', new File('../storage/app/roofing/projects/'. $project->id.'/'. $file)); } 

I need to send the file after saving to my local AWS S3 server because of the time it takes to try to upload directly to S3, and in my case this time because of the number of files that need to be saved. At the moment, everything that I will return is true in my dd (). What could be the reason for this?

 if (!empty($request->contract_asset)) { $files = $request->file('contract_asset'); foreach ($files as $file) { Storage::putFile(Carbon::now()->toDateString().'/roofing/projects/'. $project->id.'/contract-assets', $file); } } foreach (Storage::files(Carbon::now()->toDateString().'/roofing/projects/'.$project->id.'/contract-assets') as $file) { dispatch(new ProcessRoofingProjectContractAssets($file, $project)); } 

My job file.

 /** * Execute the job. * * @return void */ public function handle() { $path = Storage::disk('s3')->put('contract-assets', $this->asset, 'public'); dd($path); $this->project->addContractAsset($path); } 

UPDATE:

These are my current changes and I get the following error message. Failed because Unable to JSON encode payload. Error code: 5

 foreach ($files as $file) { $returnedStoredFile = Storage::putFile('/roofing/projects/' . $project->id . '/contract-assets/'.Carbon::now()->toDateString(), $file); dispatch(new ProcessRoofingProjectContractAssets(Storage::get($returnedStoredFile), $project)); } 
+7
laravel laravel-5
source share
1 answer

You should not pass the complete file as a parameter to your Job. Laravel will serialize it, and it will be extremely inefficient. (It is likely during this serialization that you have this problem now - Failed due to the inability to encode JSON. Error code: 5)

I assume that you have no problems downloading to a temporary folder, and you are having problems submitting the task (or completing the task).

Edit the task to get the file path as a parameter. Only as part of the task will you go to disk and read it.

Submission of the task:

 foreach ($files as $file) { $returnedStoredFile = Storage::putFile('/roofing/projects/' . $project->id . '/contract-assets/'.Carbon::now()->toDateString(), $file); dispatch(new ProcessRoofingProjectContractAssets($returnedStoredFile, $project)); } 

And having executed it:

 /** * Execute the job. * * @return void */ public function handle() { $file = Storage::get($this->asset); $path = Storage::disk('s3')->put('contract-assets', $file, 'public'); dd($path); $this->project->addContractAsset($path); } 
+5
source share

All Articles