GithubHelp home page GithubHelp logo

Comments (5)

yenfryherrerafeliz avatar yenfryherrerafeliz commented on June 10, 2024

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

I look forward to your response.

Thanks!

from aws-sdk-php.

CatoriClothing avatar CatoriClothing commented on June 10, 2024

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.

stobrien89 avatar stobrien89 commented on June 10, 2024

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.

CatoriClothing avatar CatoriClothing commented on June 10, 2024

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.

stobrien89 avatar stobrien89 commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.