frostealth / yii2-aws-s3 Goto Github PK
View Code? Open in Web Editor NEWAn Amazon S3 component for Yii2
License: MIT License
An Amazon S3 component for Yii2
License: MIT License
Hi.
Thanks for your component.
Everything is fine and pretty simple. But I have a question about getting list of object. This simple operation looks not obvious.
Have I understood it correctly, I should make custom command class, handler for it and run something like lines bellow?
class CustomCommand implements Command, HasBucket
{}
class CustomCommandHandler extends Handler
{}
$command = $s3->create(CustomCommand::class);
$result = $s3->execute($command);
Thanks in advance.
Hello,
if I add "frostealth/yii2-aws-s3": "~2.0@rc" to my composer.json I can't find the package.
Any suggestion?
Thanks
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'region' => 'ap-south-1',
'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable
'key' => 'xxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxx',
],
'options' => [
'http' => [
'verify' => false,
],
],
'defaultBucket' => 'b2b-img-search',
'defaultAcl' => 'public-read',
'debug' => false, // bool|array
],
i am getting error
my question is where should i use 'options' => [
'http' => [
'verify' => false, ],
],
value property??
2) if comment options value e.g;
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'region' => 'ap-south-1',
'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable
'key' => 'AKIAI6FFJVI5B64ZQE3Q',
'secret' => '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',
],
// 'options' => [
// 'http' => [
// 'verify' => false,
// ],
// ],
'defaultBucket' => 'b2b-img-search',
'defaultAcl' => 'public-read',
'debug' => false, // bool|array
],
then i am getting this error..
Hi there. Is there a way we can delete all the content of the given folder or the entire folder with one request?
For example I want to delete the "main/shipping_labels/test/555/" folder, or all files inside it.
The suggested method "delete" is not working for the folder. It accepts only the filename, or I can delete the folder if it is empty.
I have tried to delete the content in this way, but it is still not working -
$s3->commands()->delete("main/shipping_labels/test/555/*")->execute();
Please give an advice.
foreach ($this->defaultComponentDefinitions() as $name => $definition) {
$this->components[$name] = $this->components[$name] ?? $definition;
}
below my configuration
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable
'key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxx',
],
'region' => 'ap-south-1',
'version' => 'latest',
'defaultBucket' => 'test',
'defaultAcl' => 'public-read',
],
Usage
\Yii::$app->get('s3bucket')->upload(
$filename,
$this->file->tempName,
\Yii::$app->get('s3bucket')->defaultAcl,
[
'ContentType' => $this->file->type,
'ContentDisposition' => 'render',
]
);
Expected: file would be of defined content-type in the S3 bucket.
Actual: file is octet-stream in S3 bucket
Tried:
\Yii::$app->get('s3bucket')->put(
$filename,
$this->file->tempName,
\Yii::$app->get('s3bucket')->defaultAcl,
[
'ContentType' => $this->file->type,
'ContentDisposition' => 'render',
]
);
...and...
\Yii::$app->get('s3bucket')->put(
$filename,
fopen($this->file->tempName, 'r+'),
\Yii::$app->get('s3bucket')->defaultAcl,
[
'ContentType' => $this->file->type,
'ContentDisposition' => 'render',
]
);
...and...
\Yii::$app->get('s3bucket')->upload(
$filename,
fopen($this->file->tempName, 'r+'),
\Yii::$app->get('s3bucket')->defaultAcl,
[
'ContentType' => $this->file->type,
'ContentDisposition' => 'render',
]
);
Configuring like in readme throws error
'components' => [
// ...
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable
'key' => 'my-key',
'secret' => 'my-secret',
],
'region' => 'my-region',
'defaultBucket' => 'my-bucket',
'defaultAcl' => 'public-read',
],
// ...
],
Credentials must be an instance of Aws\Credentials\CredentialsInterface
Based on this, the config should be
'components' => [
// ...
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'credentials' => new Aws\Credentials\Credentials('my-key', 'my-secret'),
'region' => 'my-region',
'defaultBucket' => 'my-bucket',
'defaultAcl' => 'public-read',
],
// ...
],
See #3
[root@ip-xxxxx html]# nginx -v
nginx version: nginx/1.12.2
[root@ip-xxxxx html]# php --version
PHP 7.1.15 (cli) (built: Mar 1 2018 13:09:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.15, Copyright (c) 1999-2018, by Zend Technologies
I am using aws Linux ec2 with m5.large instance. I got the error "Allowed memory size of xxxx bytes exhausted ... ".
I already tried to ini_set('memory_limit','2048M');
even if i increase the limit it always gives me an error.
$s3 = Yii::$app->get('s3');
$s3->commands()->upload($upload_photo, $full)->withAcl('private')->execute();
Cool library. Lots of potential.
I received this error. Do you really need PHP7 for this? I was unable to install with satisfiable names below.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- frostealth/yii2-aws-s3 v2.0.0-beta.1 requires php >=7.0.0 -> your PHP version (5.6.10) does not satisfy that requirement.
- frostealth/yii2-aws-s3 v2.0.0-beta requires php >=7.0.0 -> your PHP version (5.6.10) does not satisfy that requirement.
- Installation request for frostealth/yii2-aws-s3 ~2.0.0@beta -> satisfiable by frostealth/yii2-aws-s3[v2.0.0-beta, v2.0.0-beta.1].
#ASK
How to move a file to another directory in a bucket
Which command that I should use ?
Thanks
In order to make other services that uses the S3 api to be contacted via this extension.
for example:
's3' => [
'class' => 'frostealth\yii2\aws\s3\Service',
'credentials' =>
'key' => 'My-Key',
'secret' => 'My-Secret',
],
'endpoint' => "https://myendpoint.com",
'region' => 'endpoitregion',
'defaultBucket' => 'defaultbucket',
'defaultAcl' => 'public-read',
],
do you can describe more of your examples? because upload() is return some data but docs doesn't has any info about it.
/frostealth/yii2-aws-s3/src/handlers/uploadCommandHandlers
protected function sourceToStream($source): StreamInterface
{
if (is_string($source)) {
$source = Psr7\try_fopen($source, 'r+');
}
return Psr7\stream_for($source);
}
Should now be
protected function sourceToStream($source): StreamInterface
{
if (is_string($source)) {
$source = Psr7\Utils::tryFopen($source, 'r+');
}
return Psr7\Utils::streamFor($source);
}
There might be more functions needs replacing, but that was the one directly affecting me. There's a list of the new functions here https://github.com/guzzle/psr7/blob/4095c77b73893521ef1c84109b95f97aa35e48b8/README.md
Earlier we are using mulitpart form upload which is going to be deprecate. So we switch to UploadAsync method to upload image to S3 but its creating empty file with no content - image file only have source file path in it. Kindly guide
To reproduce:
Yii::$app->get('s3bucket')->upload($toFile, $fromFile);
unlink($fromFile);
Uploading works by itself. Unlinking works by itself. But I can't upload and then unlink. I get "Permission Denied".
Since we have getUrl
and getCdnUrl
, I think it'd be logical if we have a CDN equivalent function for getPresignedUrl
(i.e. getPresignedCdnUrl
).
This page explains how to use Aws\CloudFront\CloudFrontClient
to generate signed CloudFront URLs:
https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/cloudfront-signed-url.html
Hi,
I was wondering if I can use something like explained here:
It uses client side encryption as I do not want to use server side.
For upload and encrypting:
`// Let's construct our S3EncryptionClient using an S3Client
$encryptionClient = new S3EncryptionClient(
new S3Client([
'region' => 'us-east-1',
'version' => 'latest',
])
);
$kmsKeyArn = 'arn-to-the-kms-key';
// This materials provider handles generating a cipher key and initialization
// vector, as well as encrypting your cipher key via AWS KMS
$materialsProvider = new KmsMaterialsProvider(
new KmsClient([
'region' => 'us-east-1',
'version' => 'latest',
]),
$kmsKeyArn
);
$bucket = 'the-bucket-name';
$key = 'the-upload-key';
$cipherOptions = [
'Cipher' => 'gcm'
'KeySize' => 256,
// Additional configuration options
];
$result = $encryptionClient->putObject([
'@MaterialsProvider' => $materialsProvider,
'@CipherOptions' => $cipherOptions,
'Bucket' => $bucket,
'Key' => $key,
'Body' => fopen('file-to-encrypt.txt'),
]);`
And for download and de-crypting this:
$result = $encryptionClient->getObject([
'@MaterialsProvider' => $materialsProvider,
'@CipherOptions' => [
// Additional configuration options
],
'Bucket' => $bucket,
'Key' => $key,
]);
Can this be done with this extension?
Thanks,
gb5256
I am trying to upload file to amazon, but I got this error
Call to undefined function GuzzleHttp\Psr7\try_fopen()
vendor\frostealth\yii2-aws-s3\src\handlers\UploadCommandHandler.php line 48
My code:
$result = $s3->commands()->upload('e:\Video\short videos\The Small Business Story – short video no captions.mp4', '/uplod/29/10/small.mp4')->withAcl('private')->execute();
How can I fix that?
Please add support for CDN urls, same as on v.1
I want to upload large files to S3, what should I do
How do you set content-type
and content-disposition
, and permissions with put()
?
Even the storage url is wrong in my opinion it uses the defaultBucket and then the s3 url. my default acl is 'public-read'
If CloudFront CDN is configured, we should have the ability to invalidate an object so that it clears from the CloudFront cache (maybe automatically if a file is being overwritten): http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html
`D:\wamp64\www\fpv1>composer require frostealth/yii2-aws-s3 ~2.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
[ErrorException]
Undefined property: Fxp\Composer\AssetPlugin\Repository\BowerRepository::$repoConfig
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...`
hi,
I have a image file in local directory, So i will upload it to aws s3 using $s3->commands()->upload('blabla')->execute(); After uploaded successfully, i want to remove local image file using php unlink() function. But
I get an error: unlink('path/to/local/file') Resource temporarily unavailable
I searched a lot in google. Some object/variable is holding on to the image for some reason...
How can i solve it?
Please explain the feasibility of using a mock service with your library. We have a requirement to test our yii2 application locally without uploading files to s3.
hello, how can i upload a file to a specific folder in my bucket
Would it be nice to have a simple method to activate s3 streamWrapper
Thanks
C
Hello,
I am trying to upgrade frostealth library from 0.2.0 to 2.0.0 ,I am facing below error:-
Problem 1
- Installation request for frostealth/yii2-aws-s3 2.0.0 -> satisfiable by frostealth/yii2-aws-s3[v2.0.0].
- Conclusion: don't install aws/aws-sdk-php 2.7.27
- frostealth/yii2-aws-s3 v2.0.0 requires aws/aws-sdk-php ~3.17 -> satisfiable by aws/aws-sdk-php[3.100.0, 3.100.1, 3.100.2, 3.100.3, 3.100.4, 3.100.5, 3.100.6, 3.100.7, 3.100.8, 3.100.9, 3.101.0, 3.101.1, 3.102.0.
I have php8.0 and aws-sdk-php 2.7.27 version on my machine.I hit below command to upgrade frostealth library version
composer require frostealth/yii2-aws-s3 2.0.0.
[InvalidArgumentException]
Package frostealth/yii2-aws-s3 at version ~2.0 has a PHP requirement incomp
atible with your PHP version (5.6.35)
When the upload()
or put()
function is used in a model's public
function, the values the s3 function returns will cause the rest of the model function to break, since a model function always requires to return true
in order to continue.
Hello, how can I fix that please
thanks
PHP Compile Error 'yii\base\ErrorException' with message 'Cannot use yii\base\Object as Object because 'Object' is a special class name'
in ../vendor/frostealth/yii2-aws-s3/src/HandlerResolver.php:9
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
As sujesting yii2 team in upgrade note:
"For extensions that have classes extending from yii\base\Object
, to be compatible with PHP 7.2, you need to require "yiisoft/yii2": "~2.0.13"
in composer.json and change affected classes to extend from yii\base\BaseObject
instead. It is not possible to allow Yii versions <2.0.13
and be compatible with PHP 7.2 or higher."
Hi!
I have my bucket on S3 and default URL is https://s3-*region*.amazonaws.com.
If I have an CNAME record to point that bucket, can I set my custom CNAME to get the bucket content.
I.E: http://mybucket.mydomain.com instead of https://s3-*region*.amazonaws.com
Thanks!
Similar to command put()
I would expect to be able to specify ContentType and generic metadata using similar methods.
Example (this currently does not work):
Yii::$app->get('s3')->commands()
->upload($pathname, $sourceFile)
->setMetadata([
'ContentType' => 'application/pdf',
'ContentDisposition' => 'attachment',
])->setContentType('application/pdf')
->execute();
Both methods setMetadata()
and setContentType()
are missing.
There seems to be no other way to set metadata either.
Возможна ли обратная совместимость со старыми версиями PHP ? 5.6 например.
Наш проект использует Ваш extension и мы на данный момент не можем обновить версию PHP до 7-й.
Hi,
I am getting below error on Windows + XAMPP environment.
AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I am using v1 for PHP 5.6
Thanks.
I have a prefix in a bucket. How to upload in that prefix?
Please don't hard require PHP 7.0 in the package requirements. I'm running >=7.0 in production and the package update broke my app until I reverted this package to use ~1.0.
Error executing "GetObject" on "https://s3.us-east-23.amazonaws.com/t-ert-34-infra-5dgdfrg/1488396616.jpeg"; AWS HTTP error: Client error:
GET https://s3.us-east-23.amazonaws.com/t-ert-34-infra-5dgdfrg/1488396616.jpeg` resulted in a 404 Not Found
response:
NoSuchKey
The specified key does not exist. (truncated...)
NoSuchKey (client): The specified key does not exist. -
NoSuchKey
The specified key does not exist.1488396616.jpeg04407CDF4F0C239BRlwa7GT13kzYCEZKPIEHkfOXXmRj19loc6rZnVt9FnoQO6dq1kAQtJneIrOYVTqsAgT/uWMiTWY=`
How about CDN url?
The default region follows the folling path : s3.amazonaws.com and the different regions : s3-.amazonaws.com
So, for example if you create a client by specifying the eu-west-1 region, it maps to the following region-specific endpoint:
s3-eu-west-1.amazonaws.com
Actually the default address is not being managed and the other endpoints follows the end point like : s3.ENDPOINT.amazonaws.com that should be not the standard according to docs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.