Comments (5)
Hi @CatoriClothing, sorry to hear about your issues. I am not sure why you are seeing this behavior but, I just did a quick test, and I was able to get the desired bucket as the action. Please see below:
Code snippet:
$s3Bucket = 'mybucket.test.com';
$user = 'TestUser';
$formInputs = ['key' => $user . '/${filename}'];
$options = [
['acl' => 'private'],
['bucket' => $s3Bucket],
['starts-with', '$key', $user . '/'],
["content-length-range", 10240, 10485760],
];
$s3Client = new S3Client([
'endpoint' => $s3Bucket,
'region' => 'us-east-1',
'use_path_style_endpoint' => true
]);
$postObject = new PostObjectV4(
$s3Client,
$s3Bucket,
$formInputs,
$options,
'+5 minutes'
);
print_r([
'attributes' => $postObject->getFormAttributes(),
'additionalData' => $postObject->getFormInputs()
]);
Output:
Array
(
[attributes] => Array
(
[action] => /mybucket.test.com
[method] => POST
[enctype] => multipart/form-data
)
[additionalData] => Array
(
[key] => TestUser/${filename}
[X-Amz-Security-Token] => REDACTED
[X-Amz-Credential] => REDACTED
[X-Amz-Algorithm] => AWS4-HMAC-SHA256
[X-Amz-Date] => 20240402T053007Z
[Policy] => REDACTED
[X-Amz-Signature] => REDACTED
)
)
This may have been an issue in the past, therefore, would you be able to either:
- Create a new test project from scratch and test?
- Make sure the AWS SDK for PHP dependency is fully updated?.
- You could delete composer.lock and then run
composer update
- You could delete composer.lock and then run
I look forward to your response.
Thanks!
from aws-sdk-php.
Hey @yenfryherrerafeliz !
Thanks for your help thus far. It seems the issue is within how the endpoint gets parsed either with the https:// prefix or without. PostObjectv4 seems to return the correct value with no https:// prefix on the endpoint when using a custom domain but then GetObject throws this error due to the lack of https:// "Custom endpoint bucket.x.com
was not a valid URI".
The GetObject is resolved when appending https:// back to the endpoint but then PostObjectv4 has the same issue.
Is there a way to have both work within a single instantiation of the S3Client?
from aws-sdk-php.
Hi @CatoriClothing,
It sounds like you don't need a path style (where the bucket is targeted in the URI path), so I definitely wouldn't recommend setting use_path_style_endpoint
to true
.
Are you expecting the resulting URI to be a host without a scheme? The SDK will default to https
if one isn't provided in either the endpoint or explicitly in the client constructor. If you want to use http
, you can prepend that to your endpoint or provide it in the client config as 'scheme' => 'http'
.
from aws-sdk-php.
hey @stobrien89 !
Hope you had an amazing Easter.
This is how we setup the S3Client
$this->S3Client = new S3Client([
'version' => 'latest',
"region" => config('services.s3.region'),
"bucket" => bucket.x.com,
"endpoint" => bucket.x.com,
"bucket_endpoint" => true,
'use_path_style_endpoint' => true,
'credentials' => [
'key' => config('services.s3.key'),
'secret' => config('services.s3.secret')
],
]);
with use_path_style_endpoint set to true we get the correct PostObject action value of bucket.x.com. Without setting use_path_style_endpoint the action is returned as bucket.x.com./bucket.x.com
when the endpoint is set to bucket.x.com the action is correct for PostObject but when using GetObject we get this error returned from the SDK when trying to create a pre-signed url "Custom endpoint bucket.x.com was not a valid URI".
When updating the endpoint to https://bucket.x.com then we are able to create pre-signed url's correctly with GetObject but it then breaks PostObject and starts returning bucket.x.com/bucket.x.com
I'm not sure how to adjust the config so that we can use both GetObject & PostObject? Tried both bucket_endpoint to true/false, use_path_style_endpoint to true/false but haven't had any luck in being able to use both GetObject & PostObject with the same S3Client
from aws-sdk-php.
Hi @CatoriClothing,
Apologies for the delay. I think what's happening here is some conflicting behavior between PostObjectV4
and our newer rules-based endpoint provider. Could you set 'endpoint_provider'
to \Aws\Endpoint\PartitionEndpointProvider::defaultProvider()
(our legacy endpoint provider) and let me know if that resolves this?
Edit: After looking at how PostObjectV4
constructs a URI, it automatically builds a path-style URI if it detects the bucket name contains a .
. This is due to S3's policy regarding virtual hosting. Setting use_path_style_endpoint
to true
is working for you here because it's incorrectly parsing the endpoint you're providing it.
Since it seems like you're expecting a virtual-hosted endpoint anyway, have you tried setting just <your_host_name>.com
for the endpoint and setting your bucket to <bucket_name>
(excluding <host_name_>.com
)?
from aws-sdk-php.
Related Issues (20)
- Use of SSO roles for PHP CLI HOT 1
- Incorrect argument type HOT 5
- fprintf(): supplied resource is not a valid stream resource HOT 4
- SignatureV4 mismatch on some requests HOT 7
- Deprecated: Using ${var} in strings is deprecated HOT 3
- Support 'OriginationNumber' when sending SMS. HOT 1
- Exception thrown in synchronous call "bleeds over" to asynchronous call HOT 3
- IRSA for Kubernetes not working HOT 3
- Argument 4 passed to Aws\Exception\AwsException::__construct() must be an instance of Exception or null HOT 3
- verifyDomainDkim method of SES Client returns validation error HOT 4
- Yum package
- InstanceProfile credentials provider causing open_basedir restriction error since 3.297.0 HOT 2
- Aws SQS: VisibilityTimeout value is zero and type is string instead integer HOT 5
- What version should I specify for MediaPackage and MediaPackageVod client? HOT 3
- File paths are not safe for Windows HOT 2
- fopen() throws Error executing "GetObject" HOT 1
- GetObject() command @http stream issue HOT 3
- Error when trying to list objects from a public S3 bucket via the listObjectsV2() function. HOT 2
- S3 PutObject doesn't work on VPN HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-php.