Better approach is to directly uploading to cloud storage.
As directly uploading needs to upload file data only once in other process you will have to first upload it to some temp file and then from that temp file to cloud storage. So as data transfer is more it would be slower and image can be unavailable also till the time job runs and move it from temp location to cloud storage.
Now let's address how to upload directly in cloud storage using
Laravel. Below steps can be followed to achieve it :-
Import CloudStorageTools
use google\appengine\api\cloud_storage\CloudStorageTools;
Create bucket url to directly uploading file
$bucket_options = ['gs_bucket_name' => $my_bucket];
$cloud_storage_upload_url = CloudStorageTools::createUploadUrl('/upload/handler', $bucket_options);
- Now above generated
$cloud_storage_upload_url
can be used in action
tag of form to upload file directly.
Example:-
<form action="{{ upload_url }}" enctype="multipart/form-data" method="post">
Footnote :- Upload url we generated would be only accessible till 10 minutes of it's creation.
Also documentation for same can be found here.