php - 在兼容的 S3 存储上获取 Invalid_Signature_V4_Authorization_Header
问题描述
我在将我的 laravel 应用程序与 S3 兼容存储连接时遇到问题。它由 IONOS 托管(链接到文档)。由于我需要一个不同的基本 URL,我安装了包exula/laravel-storage-rados-s3,它允许我配置它。我在 filesystem.php 中有这个配置(默认值在 env 函数中设置,它们被使用):
'ionos_s3' => [
'driver' => 'ceph',
'base_url' => env('IONOS_URL'),
'port' => env('S3_PORT', 443),
'scheme' => env('S3_SCHEME', 'https'),
'tls_verify' => env('S3_TLS_VERIFY', true),
'timeout' => env('S3_TIMEOUT', 10),
'credentials' => [
'key' => env('IONOS_ACCESS_KEY_ID'),
'secret' => env('IONOS_SECRET_ACCESS_KEY'),
],
'region' => '',
'bucket' => env('IONOS_BUCKET'),
'signature_version' => 'v4',
'version' => 'latest',
// Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
'use_path_style_endpoint' => env('IONOS_PATH_STYLE_ENDPOINT', false),
'cache' => [
'store' => 'database',
'expire' => 18000, #Cache S3 files for 5 hours
'prefix' => 'cache-prefix',
],
但我可以为所欲为。我总是收到以下错误消息:
Aws\S3\Exception\S3Exception
Error executing "PutObject" on "https://s3-de-central.profitbricks.com/BUCKET/32/";
AWS HTTP error: Client error: `PUT https://s3-de-central.profitbricks.com/BUCKET/32/`
resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>Invalid_Signature_V4_Authorization_Header</Code>
<Message>Null/Empty S (truncated...) Invalid_Signature_V4_Authorization_Header (client): Null/Empty SigningKey/IsoDate/Signature -
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>Invalid_Signature_V4_Authorization_Header</Code>
<Message>Null/Empty SigningKey/IsoDate/Signature</Message>
<RequestId>e7bd3a56-7882-1fc1-b68e-0cc47af2c498</RequestId>
<HostId>FVqRz72LCRTiUvVKH-VpiEXa5EX3643IbdE6Tyu0-FE</HostId>
</Error>
不幸的是,我在网上找不到任何提示Invalid_Signature_V4_Authorization_Header错误可能是由什么引起的。使用访问数据,我可以通过 S3 浏览器成功访问存储桶。我也很惊讶,尽管 use_path_style_endpoint 设置为 false,但请求仍然针对 objects.dreamhost.com/bucket 而不是 bucket.objects.dreamhost.com。
解决方案
我终于解决了这个问题。我使用了这个包 League/flysystem-aws-s3-v3 (正如 Laravel 所建议的那样)。使用以下配置(.env 文件),它终于起作用了:
S3_ACCESS_KEY_ID=[ACCESS_KEY]
S3_SECRET_ACCESS_KEY=[SECRET]
S3_DEFAULT_REGION=s3-de-central
S3_BUCKET=[BUCKET_NAME]
S3_URL=https://s3-de-central.profitbricks.com
AWS_URL=https://s3-de-central.profitbricks.com
推荐阅读
- r - 如何读出 R 列中 JSON 字符串的一个值?
- javascript - 方向平滑变化的随机游走
- ios - 如何在 (react-native)ios 上实现全景 url 图像查看器
- express - expressjs req.body 为空
- sql - 在逗号分隔值中查找包含相同值的行
- javascript - 在 Chrome 浏览器中单击返回按钮时返回页面问题
- python - python中的OpenGL因glCheckError调用而减慢
- android - 片段加载为 RecyclerView 适配器中的项目
- jquery - 如何在 Laravel 中使用 AJAX 从 URL 正确加载数据
- javascript - 用于 API 节点 api 应用程序的不带 cookie 和会话的 cusrf