I can connect to my ovh storage:
$s3Client = new S3Client(['profile' => 'default','endpoint' =>'http://storage.sbg.cloud.ovh.net', 'region' => 'SBG','version' => latest','credentials' => array('key' => $key,'secret' => $secret,)]);
and list all my containers
$result = $s3Client->listBuckets();var_dump($result);)
But I cannot create a new one:
$s3Client->createBucket(array('Bucket' => 'cont1',));
=> So I reate it on OVH web interface :swift,SBG,private,cont1.
When I would like to upload a file in this new container :
$result = $s3Client->upload('cont1', 'test.123', fopen($file_name, 'rb'), 'public-read');
I get :
PHP Fatal error: Uncaught exception 'Aws\\S3\\Exception\\S3Exception' with message 'Error executing "PutObject" on "http://moncontainer.storage.sbg.cloud.ovh.net/test.zip";
AWS HTTP error: Client error: `PUT http://moncontainer.storage.sbg.cloud.ovh.net/test.zip` resulted in a `400 Bad Request` response:\n\nMalformedXMLThe XML you provided was not well-formed (truncated...)\n MalformedXML (client): The XML you provided was not well-formed or did not validate against our published schema - \nMalformedXMLThe XML you provided was not well-formed or did not validate against our published schematx7bd76ec0ba114f32951bb-0061d553da'\n\nGuzzleHttp\\Exception\\ClientException: Client error: `PUT http://moncontainer.storage.sbg.cloud.ovh.net/test.zip` resulted in a `400 Bad Request` response:\n\nMalformedXMLThe in /home/SrvWeb/BackupOVH/Proc/JSR/aws/Aws/WrappedHttpHandler.php on line 195
but if I put 'cont1/' (with slash)
$result = $s3Client->upload('cont1/', 'test.123', fopen($file_name, 'rb'), 'public-read');
an object is created in 'cont1' but named '/test.123'
What is the good way to create a container and how to upload a file with the correct name ?
Good news... part of the answer :
To push a file in a container with the good filename :
$containername = 'moncontainer';
$result = $s3Client->upload($containername, $containername.'/'.basename($file_Path), fopen($file_Path, 'rb'), 'public-read');
Still investigating for the creation of the container :(
Related
I'm using the aws sdk to connect to an s3 bucket. I have built an IAM Policy to allow read using "s3:GetObject", "s3:GetObjectAcl" and "s3:ListBucket" and I can use the AWS cli to view objects and list files (including with listobjectsv2). When I use:
$file = $s3client->getObject([
'Bucket' => $bucket,
'Key' => $key,
]);
$body = $file->get('Body');
$body->rewind();
echo "Downloaded the file and it begins with: {$body->read(26)}.\n";
I can view file contents but when I try:
$contents = $s3client->listObjectsV2([
'Bucket' => $bucket
]);
echo "The contents of your bucket are: \n";
foreach ($contents['Contents'] as $content) {
echo $content['Key'] . "\n";
I receive a super helpful error:
Fatal error: Uncaught Error: Class 'SimpleXMLElement' not found in /var/www/html/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php:39 Stack trace: ....
It goes on but I figure it's all trash so not continuing.
I grabbed the code straight from: https://docs.aws.amazon.com/code-samples/latest/catalog/php-s3-s3_basics-GettingStartedWithS3.php.html
Any suggestions on what is wrong?
sudo apt-get install php-xml
doh
I got some problem while managing migration from PHP5 to PHP7.
Actually, what I was doing with php5, to get an URL where upload a file, was something like this:
$options = [ 'gs_bucket_name' => 'mybucket.appspot.com' ];
$myvar = $_GET['myvar'];
$upload_url = CloudStorageTools::createUploadUrl($myvar, $options);
return $upload_url;
I've uploaded the library and now I'm trying to use
Google\Cloud\Storage\StorageClient
I've converted the code above to something like this:
$bucketName = 'mybucket.appspot.com';
$objectName = $_GET['myvar'];
$storage = new StorageClient([
'scopes' => [
'https://www.googleapis.com/auth/iam',
'https://www.googleapis.com/auth/devstorage.full_control',
]
]);
$bucket = $storage->bucket($bucketName);
$object = $bucket->object($objectName);
$upload_url = $object->signedUrl(
new \DateTime('90 min'),
[
'version' => 'v4',
]
);
return $upload_url;
I got a 403 FORBIDDEN error
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/myproject#appspot.gserviceaccount.com:signBlob?alt=json` resulted in a `403 Forbidden` response:
{
"error": {
"code": 403,
"message": "IAM Service Account Credentials API has not been used in project 123456 (truncated...)
....
Some suggestions? In the PHP5 version upload is working (with the older code), so I suppose my app angine service account has the correct permissions setted.
Thanks
Solved by passing .json file for authentication.
$storage = new StorageClient([
'projectId' => "my_project",
'keyFilePath' => 'key/serviceaccount.json',
]);
Am trying to implement developer authentication using the PHP SDK but keep getting this error:
Fatal error: Uncaught
Aws\CognitoIdentity\Exception\CognitoIdentityException: AWS Error
Code: AccessDeniedException, Status Code: 400, AWS Request ID:
da162f98-fb50-11e4-937e-0bf2642a4752, AWS Error Type: client, AWS
Error Message: User: arn:aws:iam::256661818246:user/tester is not
authorized to perform:
cognito-identity:GetOpenIdTokenForDeveloperIdentity on resource:
arn:aws:cognito-identity:us-east-1:256661818246:identitypool/us-east-1:69767873-2de2-4cc7-a78f-3d18b5e9bf71,
User-Agent: aws-sdk-php2/2.8.3 Guzzle/3.9.3 curl/7.20.0 PHP/5.3.6
thrown in
/var/www/html/aws/Aws/Common/Exception/NamespaceExceptionFactory.php
on line 91
This is my sample code:
<?php
session_start();
//Include AWS client libs
require (dirname(__DIR__).'/aws/aws-autoloader.php');
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;
/* Global Vars */
$aws_region = 'us-east-1';
$aws_key = '<AWS_KEY>';
$aws_secret = '<AWS_SECRET>';
$aws_account_id = '<AWS_ACCOUNT_ID>';
$identity_pool_id = 'us-east-1:xxxx-xxxx-xxxx-xxxx';
//Initialize a Cognito Identity Client using the Factory
$client = CognitoIdentityClient::factory(array('region' => $aws_region, 'key' => $aws_key, 'secret' => $aws_secret));
/* Acquire new Identity */
$identity = $client->getOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $identity_pool_id, 'Logins' => array('login.custom.traffic' => 'jkljkasdjk')));
//Obtain Identity from response data structure
$id = $identity->get('IdentityId');
echo "IdentityId: ".$id;
?>
I suspect the error occurs while trying to get the developer Identity. What am I missing?
Reason behind this error is there might be no policy attached to the IAM user 'tester'.
You can attach an already existing policy 'AmazonCognitoDeveloperAuthenticatedIdentities' from IAM console which gives this user access to Cognito APIs including 'getOpenIdTokenForDeveloperIdentity' as well.
I have followed this tutorial http://blog.fineuploader.com/2013/08/16/fine-uploader-s3-upload-directly-to-amazon-s3-from-your-browser/ to upload images to Amazon S3 with fineuploader and uploading works fine. The problem is when I want to see a picture I have uploaded to S3.
I get the error
[06-Jan-2015 12:30:19 Europe/Berlin] PHP Fatal error: Uncaught Aws\S3\Exception\AccessDeniedException: AWS Error Code: AccessDenied, Status Code: 403, AWS Request ID: 6F9935EA1BE9F4F5, AWS Error Type: client, AWS Error Message: Access Denied, User-Agent: aws-sdk-php2/2.7.12 Guzzle/3.9.2 curl/7.24.0 PHP/5.3.28 ITR
thrown in /home/connecti/public_html/aws/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91
When I run this test exampel
<?php
require 'aws/aws-autoloader.php';
use Aws\S3\S3Client;
// Instantiate the S3 client with your AWS credentials
$s3 = S3Client::factory(array(
'key' => 'MY_KEY',
'secret' => 'MY_SECRET_KEY',
));
$bucket = 'MY_BUCKET';
// Use the high-level iterators (returns ALL of your objects).
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucket));
echo "Keys retrieved!\n";
foreach ($objects as $object) {
echo $object['Key'] . "\n";
}
// Use the plain API (returns ONLY up to 1000 of your objects).
$result = $s3->listObjects(array('Bucket' => $bucket));
echo "Keys retrieved!\n";
foreach ($result['Contents'] as $object) {
echo $object['Key'] . "\n";
}
?>
My key, secret key and bucket are correct!
Same with other examples.
What do I need to do? Can anyone give me an example how I show an image uploaded by fineuploader and if I have to do any setting on Amazon (in addition to what I have done from the fineuploader blog)?
The error message suggests that the server-side key does not have proper permissions to make a ListObjects or some related call on the bucket in question. You'll need to re-evaluate the IAM user/group associated with your server-side key and ensure it has all required assigned permissions.
I'm having some problems connecting to MS web service hosted at appharbor.com
Here's the php code:
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
try {
$client = new SoapClient("http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl", $options);
print_r($client->__call("get_praznike", array("json")));
print_r($client->get_praznike("json"));
print_r($client->__soapCall("get_praznike", array("json"), array('soapaction' => 'http://ppjparsanje.apphb.com/get_praznike')));
} catch(Excteption $e) {
echo $e->getMessage()."<br />";
}
The error is:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host
Which is strange because service seems to work fine. I have also tried to add port 14275, but no luck. Any suggestions?
Thanks in advance!
you have made a mistake the soap has version 1 na your are passing 1.2 in options then how will it connect
$soapClient = new SoapClient('http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
print_r($soapClient);
i get output:- hence due to bad code you are getting error
SoapClient Object ( [_soap_version] => 1 [sdl] => Resource id #3 )
well here i have acceses uk mail api
take a look at how i have called a method its bit diffrent
but u will get an idea
php soap client for uk mail webservice api?