Apr 30, 2021
0
Level 1
Images twice uploaded in zip in Background Job Laravel 8.23
As per the below code when using this as a background job and run queue listen to a work background job. ZIP creation and upload to AWS working fine.
But the same files zipped twice in zipping.
$order = AppOrder::find($this->id);
$user = User::find($order->user_id);
Config::set('filesystems.disks.s3.bucket', $user->aws->bucket);
foreach($this->filelist as $list){
$imgor = Photo::find($list->id);
if($order->upload_type == 'Web Upload'){
$zipper = new Madzipper;
if(file_exists(public_path('zip/'.$order->order_id.'.zip'))){
$zipper->zip(public_path('zip/'.$order->order_id.'.zip'))->addString($imgor->image,Storage::disk('s3')->get($order->name.'/input/'.$imgor->image));
}else{
$zipper->make(public_path('zip/'.$order->order_id.'.zip'))->addString($imgor->image,Storage::disk('s3')->get($order->name.'/input/'.$imgor->image));
}
$zipper->close();
}
}
$order->image_quantity = count($this->filelist);
if ($order->upload_type == 'Web Upload') {
Storage::put($order->name.'/input/zip/'.$order->order_id.'.zip', file_get_contents(public_path('zip/'.$order->order_id.'.zip')));
File::delete(public_path('zip/'.$order->order_id.'.zip'));
}
$this->info('ZIP created');
Please or to participate in this conversation.