I cannot find uploaded archive to amazon s3 glacier using php - php

I have uploaded files to Amazon S3 Glacier using PHP as per code below. Am sure that the file is uploaded to my free Glacier S3 Account as I can print uploaded files details, archiveId etc.
Here is my problem: I cannot access the uploaded file in my Glacier S3 vault. My Vault is empty. Please where can I find my uploaded files. Is there something like permission needed on my own end. am using free account
Here is the code:
require 'vendor/autoload.php';
use Aws\Glacier\GlacierClient;
use Aws\Glacier\TreeHash;
$client = new GlacierClient([
'version' => 'latest',
'region' => 'my region here',
'credentials' => [
'key' => 'my key here',
'secret' => 'my secret here'
]
]);
$filename ='test.txt';
$result = $client->uploadArchive([
'accountId' => 'my accountid here',
'archiveDescription' => 'my first desc',
'body' => fopen($filename, 'r'),
'checksum' => '',
'contentSHA256' => '',
'sourceFile' => 'test.txt',
'vaultName' => 'my-vaultname-here',
]);
echo "success uploaded;
echo $archiveId = $result->get('archiveId');

The code above works fine as I stated earlier in the post. I finally read amazon glacier documentations and I found out the any uploaded files can show up within 1 to 48 hours depending on the archived region. The archieved has been showed. it seems to take us-east region to archive the inventory after 8-9 hours since uploads. Thanks

Related

Have a problem with cloudfront signed urls (No account found for the given parameters)

I'm trying to create signed urls from cloudfront with aws-sdk-php
I have created both Distributions WEB and RTMP
and this is the code i used to do that
this is start.php
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\CloudFront\CloudFrontClient;
$config = require('config.php');
// S3
$client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-2',
]);
// CloudFront
$cloudfront = CloudFrontClient::factory([
'version' => 'latest',
'region' => 'us-east-2',
]);
and this is config.php
<?php
return [
's3'=>[
'key' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX',
'bucket' => 'hdamovies',
'region' => 'us-east-2',
],
'cloudFront' => [
'url' => 'https://d2t7o0s69hxjwd.cloudfront.net',
],
];
and this is index.php
<?php
require 'config/start.php';
$video = 'XXXXXXXXXXX.mp4';
$expiry = new DateTime( '+1 hour' );
$url = $cloudfront->getSignedUrl([
'private_key' => 'pk-XXXXXXXXXXXXXXXXXXXXX.pem',
'key_pair_id' => 'XXXXXXXXXXXXXXXXXXXXX',
'url' => "{$config['cloudFront']['url']}/{$video}",
'expires' => strtotime('+10 minutes'),
]);
echo "Downlod";
When i click on the link i get that error
<Error>
<Code>KMS.UnrecognizedClientException</Code>
<Message>No account found for the given parameters</Message>
<RequestId>0F0A772FE67F0503</RequestId>
<HostId>juuIQZKHb1pbmiVkP7NVaKSODFYmBtj3T9AfDNZuXslhb++LcBsw9GNjpT0FG8MxgeQGqbVo+bo=</HostId></Error>
What is the problem here and how can i solve that?
CloudFront does not support downloading objects that were stored, encrypted, in S3 using KMS Keys, apparently because the CloudFront Origin Access Identity is not an IAM user, so it's not possible to authorize it to have the necessary access to KMS.
https://forums.aws.amazon.com/thread.jspa?threadID=268390
I had this issue and had it resolved after setting up the correctly Identities. However, I had a lot of issues with the error even after setting things up correctly. This was because I was attempting to download a file that was originally uploaded when the bucket was KMS encrypted, then later when I changed it to SSE-S3, it still was throwing a KMS error.
After reuploading the file, it seemed to work without any issues. Hope this helps someone else

Uploading file to S3 using presigned URL in PHP

I am developing a Web Application using PHP. In my application, I need to upload the file to the AWS S3 bucket using Presigned URL. Now, I can read the private file from the S3 bucket using pre-signed like this.
$s3Client = new S3Client([
'version' => 'latest',
'region' => env('AWS_REGION', ''),
'credentials' => [
'key' => env('AWS_IAM_KEY', ''),
'secret' => env('AWS_IAM_SECRET', '')
]
]);
//GetObject
$cmd = $s3Client->getCommand('GetObject', [
'Bucket' => env('AWS_BUCKET',''),
'Key' => 'this-is-uploaded-using-presigned-url.png'
]);
$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');
//This is for reading the image. It is working.
$presignedUrl = (string) $request->getUri();
When I access the $presignedUrl from the browser, I can get the file from the s3. It is working. But now, I am uploading a file to S3. Not reading the file from s3. Normally, I can upload the file to the S3 like this.
$client->putObject(array(
'Bucket' => $bucket,
'Key' => 'data.txt',
'Body' => 'Hello!'
));
The above code is not using the pre-signed URL. But I need to upload the file using a pre-signed URL. How, can I upload the file using a pre-signed URL. For example, what I am thinking is something like this.
$client->putObject(array(
'presigned-url' => 'url'
'Bucket' => $bucket,
'Key' => 'data.txt',
'Body' => 'Hello!'
));
How can I upload?
It seems reasonable that you can create a pre-signed PutPobject command by running:
$cmd = $s3Client->getCommand('PutObject', [
'Bucket' => $bucket,
'Key' => $key
]);
$request = $s3Client->createPresignedRequest($cmd, '+20 minutes')->withMethod('PUT');
Then you might want to perform the PUT call from PHP using:
file_put_contents(
$request->getUri(),
'Hello!',
stream_context_create(['http' => [ 'method' => 'PUT' ]])
);
If you want to create a URL that a browser can submit, then you need to have the browser send the file as a form POST. This AWS documentation explains how to create a pre-signed POST request with the fields that you then need to put into an HTML form and display to the user: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-presigned-post.html
Also, this answer might be useful: https://stackoverflow.com/a/59644117/53538

Amazon aws - s3 bucket not uploading image - It creates only the key

I am using Laravel 5.0 and using "aws/aws-sdk-php-laravel": "~2.0"
Here is my script to upload the image
$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
'Bucket' => 'greenhoppingbucket',
'Key' => 'sups',
'Body' => Input::file('file'),
));
After the execution only the key is uploaded in the s3 bucket
i.e., sups is created bucket but not the image.
What is the mistake i am doing and how can i fix this
try this:
$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
'Bucket' => 'greenhoppingbucket',
'Key' => 'sups',
'Body' => File::get((string)Input::file('file')),
));
dont forget to add use File;
when you do 'Body' => Input::file('file'), you bassiclly putting the temp path into the body instead of the content of the file.
the File::get is simply getting the contents of a file

The last step of a AWS EC2 to S3 file upload

I have this code :
require '/home/ubuntu/vendor/autoload.php';
$sharedConfig = [
'region' => 'us-west-2',
'version' => 'latest'
];
$sdk = new Aws\Sdk($sharedConfig);
$s3Client = $sdk->createS3();
$result = $s3Client->putObject([
'Bucket' => 'my-bucket',
'Key' => $_FILES["fileToUpload"]["name"],
'Body' => $_FILES["fileToUpload"]["tmp_name"]
]);
It works, basically. It sends a file to S3. But it apparently sends it badly since it always shows as a corrupted file... Can anyone tell me what I am doing wrong?
To be specific - the image I am uploading is a jpg image and when I try to look at it on the S3 instance, I am told that it "cannot be displayed because it contains errors"

Upload Progress percent in ajax upload to S3 bucket using the php-sdk with Mulitpart upload

I am trying to upload a video file to S3 bucket using the PHP-SDK and a multipart upload. I managed to make it work via ajax already, but I want to know how to calculate and return the progress? I did a lot of research already but have not found any solutions yet.
Any help highly appreciated.
Here's an example using putObject, which can be converted into MultipartUpload:
$client = new S3Client(/* config */);
$result = $client->putObject([
'Bucket' => 'bucket-name',
'Key' => 'bucket-name/file.ext',
'SourceFile' => 'local-file.ext',
'ContentType' => 'application/pdf',
'#http' => [
'progress' => function ($downloadTotalSize, $downloadSizeSoFar, $uploadTotalSize, $uploadSizeSoFar) {
printf(
"%s of %s downloaded, %s of %s uploaded.\n",
$downloadSizeSoFar,
$downloadTotalSize,
$uploadSizeSoFar,
$uploadTotalSize
);
}
]
]);
This is explained in the AWS docs - S3 Config section. It works by exposing GuzzleHttp's progress property-callable, as explained in this SO answer.
Have you looked into these links.
http://codeseekah.com/2012/03/09/file-upload-progress-in-php-5-4/
https://github.com/Widen/fine-uploader

Categories