Connecting to Amazon s3 from Google App Engine PHP - php

I'm working on a PHP application hosted on Google App Engine which requires access to objects stored in an S3 Bucket. I've looked at the APIs available for Amazon S3 and all of them make use of CURL. But CURL is not allowed in Google App Engine.
Is there a way to access Bucket Contents and user other functions available in the S3 API without using CURL in PHP?

Amazon recently released a wrapper for file_get_contents which is what urlfetch uses - so take a look at http://blogs.aws.amazon.com/php/blog/tag/stream - looks like you can do $contents = file_get_contents("s3://{$bucket}/{$key}");
You should look at the URL Fetch docs - it's the google recommended way to do calls https://developers.google.com/appengine/docs/php/urlfetch/

Use the URL Fetch API instead of CURL
https://developers.google.com/appengine/docs/php/urlfetch/

Related

php Api hosted on AWS s3 bucket

I wanna host a php file that retrieve data from a mysql DB how ever aws is not authorizing POST method.
I need to know how can I add the code in PHP knowing I already configured the Bucket policy and CORS
You can only serve static content from an S3 - PHP will not be processed.
If you want to set up a dynamic PHP website on AWS have a look at LightSail and its LAMP stack.
You should try Amazon API Gateway.

Can files be uploaded to a compute engine on GCP using an application page written in php/html?

Can we upload image files to a GCP running compute engine directly using PHP?
I know that it can be done using the backend ssh on GCP.
I have a solution that works in my local system to upload files but does not work on GCP.
Based on initial research it appears that GCP does not allow file upload directly.
Need confirmation though or if there is a way in which file upload can work, please enlighten.
I do not think it can be done directly through php, through ssh yes.
You can upload files with PHP.
If you want to upload to the server local disk, things become a bit simpler. Just ensure you have PHP configured for upload: PHP File Upload
If you want to upload to Google Storage, say to a bucket, you'd need to authenticate and get access there. Google Cloud SDK can provide this. Then you can install API Client Libraries for PHP and optional Cloud SDK components. That way you might call gcloud shell command or use API. Cloud SDK will provide transparent connection and authentication for you so that you can upload to the Google Storage.
Please see:
Cloud SDK
Google API Client Libraries

How can i read an s3 file without S3 SDK using aws credentials?

so i want to read an S3 file using PHP without going to the url for security purposes.
I cannot use sdk since im using lambda and does not allow me to use php-filter and/or openssl 10.0.2
I found lots of Curl examples to put/post files but is there a way to do the get using all the credentials?
Thank you in advance
As you cannot use Lambda and you don't want to use API then the only option is to use CLI. As I am not a PHP guy I don't know will CLI works with PHP but give it a try. If you want to get object from S3 using CLI then see the sample below,
aws s3api get-object --bucket text-content --key dir/my_images.tar.bz2 my_images.tar.bz2
Please read the documentation - http://docs.aws.amazon.com/cli/latest/reference/s3api/get-object.html
I think what you're looking for is a PHP library that will run in AWS Lambda and that can interface with Amazon S3. Amazon doesn't currently offer PHP language support in Lambda, so you might want to look at one of these options:
3rd-party PHP S3 client, for example amazon-s3-php-class
create your own S3 requests to the S3 REST API
3rd-party options for running PHP in Lambda (examples here and here)

Is there anyway to connect to Google Cloud Storage from Google Compute Engine?

Currently I am using google app engine for my php project. I decided to migrate my project to Google Compute Engine, but i could not connect to Google Cloud Storage through php. Is there anyway to work around this issue?
Update:
I found that it is achievable and i need some example of using Server API to grab the storage content. This is what i did.
require_once 'GoogleAPI/autoload.php';
$projectId = "dummyid";
$client = new Google_Client();
$client->setApplicationName("Gave");
$client->setDeveloperKey("SERVERKEY");
$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$storage = new Google_Service_Storage($client);
$buckets = $storage->buckets->listBuckets($projectId);
foreach ($buckets['items'] as $bucket) {
printf("%s\n", $bucket->getName());
}
But it still doesnt work. Does server key has limited to access some control ? It gives me an error 500.
You can certainly use Google Cloud Storage (GCS) from Google Compute Engine (GCE). You'll find it's one of the very fastest ways to access GCS. You cannot, however, access GCS using the same App Engine PHP libraries when you're not using App Engine.
The canonical client library for using PHP from environments other than AppEngineis Google APIs Client Library for PHP. You can find demonstrations and tutorials on accessing GCS with that library here: https://cloud.google.com/storage/docs/json_api/v1/json-api-php-samples
As a second option, the new gcloud-php project has basic support for GCS.
Finally, as a third option, the public APIs for accessing GCS directly with HTTP requests are well documented and work very well from GCE.

Insert object to Google Cloud Storage using PHP

To be honest, I am really frustrated with the lack of document of Google Cloud Storage with PHP. Most of what I found in here (Stackoverflow) is out of date.
Here is my attempt:
$postbody = array('data' => file_get_contents('e.png'));
$gso = new Google_Service_Storage_StorageObject();
$gso->setName('testing');
$gso->setContentType('images/png');
$service->objects->insert($bucket_name, $gso, $postbody);
The error message
(400) Upload requests must be sent to /upload/*. Re-send request to the same path, but with an /upload prefix.
From Google Cloud Storage JSON API, I understand that I need to use upload/storage/v1/b/bucket_name/o instead of storage/v1/b/bucket_name/o, but how do I do it with Google Cloud Storage PHP Client API?
I managed to build a small script that uploads big files to GCS.
I used Google APIs Client Library for PHP
Find it in github https://github.com/guillefd/Backup-manager-gcs
This library manages the file upload (big files) https://github.com/guillefd/Backup-manager-gcs/blob/master/application/libraries/Googlecloudstorage.php
I´m actually using it in many sites and works quite fine.

Categories