A
A
Analka2021-06-11 23:22:57
Laravel
Analka, 2021-06-11 23:22:57

Why can this error pop up in yandex cloud + Laravel?

I'm trying to save an image in yandex.cloud

$image = $request->file('image');        
$path = Storage::disk('yandex')->put($this->slug($image->getClientOriginalName(), $image->getClientOriginalExtension()), 'tmp');

but gives out
Error executing \"PutObject\" on \"http://rzo.storage.yandexcloud.net/logo-ptk-dveri-ekspertjpg.jpg\"; AWS HTTP error: Client error: `PUT http://rzo.storage.yandexcloud.net/logo-ptk-dveri-ekspertjpg.jpg` resulted in a `403 Forbidden` response:\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calcul (truncated...)\n SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you provided. Check your key and signing method. - <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><Resource>/logo-ptk-dveri-ekspertjpg.jpg</Resource><RequestId>434c2e1f305e7983</RequestId><CanonicalRequest>PUT\n/logo-ptk-dveri-ekspertjpg.jpg\n\nhost:rzo.storage.yandexcloud.net\nx-amz-acl:private\nx-amz-content-sha256:c42edefc75871e4ce2146fcda67d03dda05cc26fdf93b17b55f42c1eadfdc322\nx-amz-date:20210611T201833Z\n\nhost;x-amz-acl;x-amz-content-sha256;x-amz-date\nc42edefc75871e4ce2146fcda67d03dda05cc26fdf93b17b55f42c1eadfdc322</CanonicalRequest><CanonicalRequestBytes>50 55 54 0a 2f 6c 6f 67 6f 2d 70 74 6b 2d 64 76 65 72 69 2d 65 6b 73 70 65 72 74 6a 70 67 2e 6a 70 67 0a 0a 68 6f 73 74 3a 72 7a 6f 2e 73 74 6f 72 61 67 65 2e 79 61 6e 64 65 78 63 6c 6f 75 64 2e 6e 65 74 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 72 69 76 61 74 65 0a 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3a 63 34 32 65 64 65 66 63 37 35 38 37 31 65 34 63 65 32 31 34 36 66 63 64 61 36 37 64 30 33 64 64 61 30 35 63 63 32 36 66 64 66 39 33 62 31 37 62 35 35 66 34 32 63 31 65 61 64 66 64 63 33 32 32 0a 78 2d 61 6d 7a 2d 64 61 74 65 3a 32 30 32 31 30 36 31 31 54 32 30 31 38 33 33 5a 0a 0a 68 6f 73 74 3b 78 2d 61 6d 7a 2d 61 63 6c 3b 78 2d 61 6d 7a 2d 63 6f 6e 74 65 6e 74 2d 73 68 61 32 35 36 3b 78 2d 61 6d 7a 2d 64 61 74 65 0a 63 34 32 65 64 65 66 63 37 35 38 37 31 65 34 63 65 32 31 34 36 66 63 64 61 36 37 64 30 33 64 64 61 30 35 63 63 32 36 66 64 66 39 33 62 31 37 62 35 35 66 34 32 63 31 65 61 64 66 64 63 33 32 32</CanonicalRequestBytes><SignatureProvided>7dd87fe219bd7338d44231341b8b527d4a7191694f729a671f80513072a30be1</SignatureProvided><StringToSign>AWS4-HMAC-SHA256\n20210611T201833Z\n20210611/ru-central1-a/s3/aws4_request\nb3d1cffa8db5020360b5d561e596475fae0a0638712ef9fedc3206357b0ea756</StringToSign><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 32 31 30 36 31 31 54 32 30 31 38 33 33 5a 0a 32 30 32 31 30 36 31 31 2f 72 75 2d 63 65 6e 74 72 61 6c 31 2d 61 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 62 33 64 31 63 66 66 61 38 64 62 35 30 32 30 33 36 30 62 35 64 35 36 31 65 35 39 36 34 37 35 66 61 65 30 61 30 36 33 38 37 31 32 65 66 39 66 65 64 63 33 32 30 36 33 35 37 62 30 65 61 37 35 36</StringToSignBytes></Error>

in filesystems.php indicated
'yandex' => [
            'driver' => 'yandexcloud',
            'key' => env('YANDEX_ACCESS_KEY'),
            'secret' => env('YANDEX_ACCESS_SECRET_KEY'),
            'bucket' => env('YANDEX_ACCESS_BAKET_NAME'),
            'region' => 'ru-central1-a',
        ],

and provider
class YandexObjectStorageServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Storage::extend('yandexcloud', function($app, $config) {
            $client = new S3Client([
                'credentials' => [
                    'key'    => $config['key'],
                    'secret' => $config['secret'],
                ],
                'region' => $config['region'],
                'version' => 'latest',
                'endpoint' => 'http://storage.yandexcloud.net/',
            ]);

            return new Filesystem(new AwsS3Adapter($client, $config['bucket']));
        });
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question