I'm currently trying to upload to the Firebase Cloud Storage using php, but running into an issue.
I have a form in html, that takes the uploaded file (in my case an image), and passes it to a php file.
This image is very small, 12.8kB, and a JPEG image.
The php file takes the image, and tries to upload it to the storage. My current php code is roughly:
$storage = new StorageClient(['projectId' => '<my_project_id> ']);
$bucket = $storage->bucket('images');
$bucket->upload($_FILES['imageToUpload']['tmp_name']);
I can get it to print the bucket name, and it's details, so I know it's not that part that is causing the error.
The error I get is,
Fatal error: Uncaught InvalidArgumentException: A name is required when data is of type string or null.
in /var/www/html/Images/vendor/google/cloud-storage/src/Bucket.php:258
Stack trace: #0 /var/www/html/Images/uploadImage.php(74): Google\Cloud\Storage\Bucket->upload('/tmp/phpA9SAM8')
#1 {main} thrown in /var/www/html/Images/vendor/google/cloud-storage/src/Bucket.php on line 258
Oh, I am also working on 16.04 Ubuntu if that matters, with apache2. (But I've been able to upload to my own computer with php. Just refactoring to use Firebase now)
EDIT: When I've changed my code to be
$bucket->upload(
file_get_contents($_FILES['imageToUpload']['tmp_name']),
[
'name' => $_FILES['imageToUpload']['name']
]
);
I'm getting the error:
Fatal error: Uncaught Google\Cloud\Core\Exception\NotFoundException: { "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "Not Found" } ], "code": 404, "message": "Not Found" } } in /var/www/html/Images/vendor/google/cloud-core/src/RequestWrapper.php:263
Stack trace: #0 /var/www/html/Images/vendor/google/cloud-core/src/RequestWrapper.php(168): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(GuzzleHttp\Exception\ClientException))
#1 /var/www/html/Images/vendor/google/cloud-core/src/Upload/MultipartUploader.php(64): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#2 /var/www/html/Images/vendor/google/cloud-storage/src/Bucket.php(268): Google\Cloud\Core\Upload\MultipartUploader->upload()
#3 /var/www/html/Images/uploadImage.php(75): Google\Cloud\Storage\Bucket->upload('/tmp/phpR2vYYg', Array)
#4 {main} thrown in /var/www/html/Images/vendor/google/cloud-core/src/RequestWrapper.php on line 263