folder_service = $folder_service; $this->bucket = $bucket; } /** * @param UploadedFile $file * @param $folder_name * @param bool $is_image * @return File * @throws \Exception */ public function build(UploadedFile $file, $folder_name, $is_image = false){ $attachment = new File(); try { $local_path = Storage::putFileAs(sprintf('/public/%s', $folder_name), $file, $file->getClientOriginalName()); $folder = $this->folder_service->findOrMake($folder_name); $local_path = Storage::disk()->path($local_path); $attachment->setParent($folder); $attachment->setName($file->getClientOriginalName()); $attachment->setFilename(sprintf("assets/%s/%s", $folder_name, $file->getClientOriginalName())); $attachment->setTitle(str_replace(array('-', '_'), ' ', preg_replace('/\.[^.]+$/', '', $file->getClientOriginalName()))); $attachment->setShowInSearch(true); if ($is_image) // set className $attachment->setImage(); $this->bucket->put($attachment, $local_path); $attachment->setCloudMeta('LastPut', time()); $attachment->setCloudStatus('Live'); $attachment->setCloudSize(filesize($local_path)); } catch (\Exception $ex){ Log::error($ex); throw $ex; } return $attachment; } }