spatie/laravel-medialibrary Google Cloud Storage compatibility - php

I have a laravel app that uploads pictures to S3 or to local storage alright.
But I can't upload to GCS.
Is laravel-medialibrary compatible with any GCS library?
I'm asking this because I keep on getting;
"message "Call to undefined method League\Flysystem\Filesystem::makeDirectory()"
exception "Error"
file "/var/www/html/vendor/spatie/laravel-medialibrary/src/MediaCollections/Filesystem.php"
line 317"
When I look at Filesystem, it has createDirectory() instead of makeDirectory().
So is there any library that I can use to upload to GCS?

You can use this package .
You can install the package via composer:
composer require spatie/laravel-google-cloud-storage

Related

Getting started with Google Storage

I am having really difficult time trying to connect Google Storage. All I need is to be able to upload PDF file to a bucket that I've created on Google Storage Console. The documentation seems to be all over the place and lacking simple examples of PHP code. So here's what I've done so far:
Installed cloud storage
$ composer require google/cloud-storage
Added billing as per Google's requirement. Enabled Cloud Storage API. Created project and added a bucket.
Attempted to use the following example:
require '../vendor/autoload.php';
define("PROJECT_ID", "my-project");
define("BUCKET_NAME", "my-bucket");
$client = new Google_Client();
$client->setApplicationName("API_Cloud_Storage");
$client->useApplicationDefaultCredentials();
$client->setScopes(["https://www.googleapis.com/auth/cloud-platform"]);
$service = new Google_Service_Storage($client);
$request = $service->buckets->listBuckets(PROJECT_ID);
foreach ($request["items"] as $bucket)
printf("%s\n", $bucket->getName());
Keep on getting error on
Fatal error: Uncaught Error: Class 'Google_Client' not found in /home/domain/public_html/test.php:11 ...
I know the vendor/autoload.php file is loading because I have no issues with AWS in a different script.
I didn't even pass the first line. What am I missing?
You have the documentation page for Cloud Storage Client Libraries with a PHP sample and detailed instructions. There's also a link to the GitHub repo for that quickstart, in addition to the one shared by ceejayoz in the comments.

Error retrieving credentials from the instance profile metadata server: s3 with Laravel

I am developing a web application using Laravel. In my application, I develop a feature for uploading the file to the server. But, I will store the files in the Amazon S3 bucket instead. So, I am just following the Laravel official documentation - https://laravel.com/docs/5.5/filesystem. But I am getting an error.
First I run this command to install required package in the terminal
composer require league/flysystem-aws-s3-v3
Then in the environment file, I added these variable
AWS_IAM_KEY=xxxxxxx
AWS_IAM_SECRET=xvxxxx
AWS_REGION=eu-west-2
AWS_BUCKET=xxxxxxx
Then in the controller, I upload like this.
$request->file('photo_file')->store(
'activity_files/'.uniqid(), 's3'
);
When I upload the file, it is giving me this error.
Error retrieving credentials from the instance profile metadata server. (cURL error 7: Failed to connect to 169.254.169.254 port 80: Network unreachable (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
What is wrong with my code?

PHP: include files without composer

I have to check the InAppPurchases receipts with my PHP server.
I would use this script in order to achieve my goal.
I'm running on a shared hosting server, so I'm not able to install or use composer. How can I still use and include the above mentioned PHP script?
I already included the following lines:
require '../lib/validate_inapp_purchase/iTunes/PurchaseItem.php';
require '../lib/validate_inapp_purchase/iTunes/Response.php';
require '../lib/validate_inapp_purchase/iTunes/Validator.php';
use ReceiptValidator\iTunes\Validator as iTunesValidator;
But the script throws the following error:
Fatal error: Class 'GuzzleHttp\Client' not found in /homepages/11/htdocs/app/lib/validate_inapp_purchase/iTunes/Validator.php on line 130
Use composer locally (on your machine) and then upload everything (including vendor folder) to the hosting server.

installing Google Client Library for Google Analtics PHP

first of all I am new to this topic, so I hope my question is not too stupid.
I want my website to have PHP access to Google Analytics metrics. I followed every step of this description from google. Unfortunately when I upload everything on my server and try to run the test-site, I always get the following error-message:
Fatal error: Uncaught exception 'Exception' with message 'This library
must be installed via composer or by downloading the full package. See
the instructions at
https://github.com/google/google-api-php-client#installation.' in
/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php:14
Stack trace: #0
/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(8):
require_once() #1
/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(104):
getService() #2 {main} thrown in
/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php
on line 14
So apparently there is something wrong with the embedding of the Google client library. In the error message it says I have to use Composer, but in the GitHub documentation they say, manual download would be fine as well. I think in the end this shouldn't make any difference? I am not familiar with composer or GitHub, this is why i downloaded it manually.
I uploaded it on the server and put it into the same directory like the HelloAnalytics.php. I address it in HelloAnalytics.php via
require_once 'google-api-php-client-master/src/Google/autoload.php'
From the looks of it you are using the wrong autoloader.
src/Google/autoload.php looks for the composer autoloader and if it doesn't exist it throws the exception you are getting. Since you didn't install using Composer it is not found and that exception is thrown.
If you clone the repository using git you will have the correct SPL autoloader. If you download the package it uses the composer autoloader.
Try downloading using:
git clone -b v1-master https://github.com/google/google-api-php-client.git
Or switch to the v1-master branch and use this autoloader instead. You will see that file differs between the master branch and the v1-master branch.
to avoid AUTOLOADer error, install MASTER-V1 version:
https://github.com/google/google-api-php-client/tree/v1-master
p.s. if you will get other error, then ensure that you have correctly included the "SERVICE EMAIL" (that is like: xxxxxx#analytics-xxxxx.iam.gserviceaccount.com ).

ez components and AWS PHP SDK makes ez components freak out

I try to work with ez Components and AWS PHP SDK at the same time.
I have a file called resize.php which is just handling resizing images using the ez Components ImageTransition tools.
I queue the image for resize in Amazon AWS SQS. If I load the AWS PHP SDK and ez Components in the same file, PHP always complains about not finding the ez Components classes.
Code looks something like this:
amazonSQS.php:
require 'modules/resize.php';
require 'modules/aws/sdk.class.php';
$sqs = new AmazonSQS();
$response = $sqs->send_message($queue_url, $message);
resize.php:
function resize_image($filename) {
$settings = new ezcImageConverterSettings(
array(
//new ezcImageHandlerSettings( 'GD', 'ezcImageGdHandler' ),
new ezcImageHandlerSettings( 'ImageMagick', 'ezcImageImagemagickHandler' ),
)
);
Error message:
Fatal error: Class 'ezcImageConverterSettings' not found in /home/www.com/public_html/modules/resize.php on line 10
If I call resize.php from another PHP file which has AWS not included, it works fine.
I load ezComponents like this:
require 'ezc/Base/ezc_bootstrap.php';
It is installed as a PEAR package.
Any idea someone?
The PHP classes of Apache Zeta / eZ Components can be conveniently used from within your PHP script. You don't have to use any require or include statements for any of the Apache Zeta Components classes that you use, this is because of the integrated autoload mechanism which can locate the classes for you when you instantiate or use them otherwise.
There are three different ways of getting the autoload mechanism going:
Normal autoload, if you require a custom autoload function
Bootstrap file, if you only use Apache Zeta autoloading
SPL autoload, if you need to register several autoload functions
These 3 ways are fully documented here

Categories