- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我觉得在这里发布这个很奇怪,但由于 SO 是 Google API 支持的唯一官方 channel ,我想我需要在这里提问。
If you have API, tool usage, or other software development-related questions, search for and post questions on Stack Overflow, using the official google-cloud-storage tag.
好的,就这样吧。我花了两天的大部分时间努力让 Google Storage 在 Amazon 的 PHP SDK 的 v3 版本(最新)上运行。我不能使用旧版本的 SDK,因为我试图坚持使用 Laravel 5.1 的文件系统,而不必为 Google Storage 编写全新的驱动程序。我相信这符合 Google 宣传 Google Storage 的精神:
https://cloud.google.com/storage/docs/migrating
In a simple migration from Amazon S3 to Google Cloud Storage, you can use your existing tools and libraries for generating authenticated REST requests to Amazon S3, to also send authenticated requests to Google Cloud Storage. The changes you need to make to your existing tools and libraries are described in this section.
To get set up for a simple migration do the following:
Set a default Google project.
Get a developer key.
In your existing tools or libraries, make the following changes: Change the request endpoint to use the Google Cloud Storage request endpoint. Replace the Amazon Web Services (AWS) access and secret key with the corresponding Google Cloud Storage access key and secret key (collectively called your Google developer key).
That's it! At this point you can start using your existing tools and libraries to send keyed-hash message authentication code (HMAC) requests to Google Cloud Storage.
多好的一个音调!让我们尝试使用可使用 gsutil 工作的互操作性凭证。
$client = new S3Client([
'credentials' => [
'key' => 'GOOGxxxxxxxxxxxxxxx',
'secret' => 'ZfcOTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
'region' => 'US',
'version' => 'latest',
'endpoint' => 'https://storage.googleapis.com',
]);
try {
$result = $client->putObject(array(
'Bucket' => 'devtest',
'Key' => 'test',
'Body' => 'Hello world'
));
echo $result['ObjectURL'];
} catch (\Aws\S3\Exception\S3Exception $e) {
// The AWS error code (e.g., )
echo $e->getAwsErrorCode() . "\n";
// The bucket couldn't be created
echo $e->getMessage() . "\n";
}
不起作用。你得到一个“不正确的身份验证 header ”。让我们看一下该 header 。
AWS4-HMAC-SHA256 Credential=GOOGGUxxxxxxxxxxx/20150611/US/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=9c7de4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
此时我创建了一个关于此的 SO 帖子,有人建议我添加 'signature' => 'v2'。
Google Storage Incorrect Authorization Header with Amazon S3 PHP SDK v3
让我们试试看:
$client = new S3Client([
'credentials' => [
'key' => 'GOOGxxxxxxxxxxxxxxx',
'secret' => 'ZfcOTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
'region' => 'US',
'version' => 'latest',
'endpoint' => 'https://storage.googleapis.com',
'signature' => 'v2',
]);
运气不好。同样的错误。授权 header 没有改变。让我们看一下 S3Client 的代码,看看“签名”是如何使用的:
public function createPresignedRequest(CommandInterface $command, $expires)
{
/** @var \Aws\Signature\SignatureInterface $signer */
$signer = call_user_func(
$this->getSignatureProvider(),
$this->getConfig('signature_version'),
$this->getApi()->getSigningName(),
$this->getRegion()
);
return $signer->presign(
\Aws\serialize($command),
$this->getCredentials()->wait(),
$expires
);
}
事实并非如此。所以现在我们偏离了 S3 的官方文档,因为他们说了同样的话:
http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html
这不是“签名”,而是“签名版本”。让我们将其更改为 v2。
$client = new S3Client([
'credentials' => [
'key' => 'GOOGxxxxxxxxxxxxxxx',
'secret' => 'ZfcOTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
'region' => 'US',
'version' => 'latest',
'endpoint' => 'https://storage.googleapis.com',
'signature_version' => 'v2',
]);
至少这次我们得到了一个不同的错误!
UnresolvedSignatureException in SignatureProvider.php line 61: Unable to resolve a signature for v2/s3/US. Valid signature versions include v4 and anonymous.
所以,在玩弄了两天之后,这似乎是不可能的,至少不是 Google 希望您相信他们的推销那样轻松。我根本无法让它工作,所以我希望这里有人可以对此有所了解。要么我错过了一些重要的东西,要么谷歌错误地宣传谷歌存储使用亚马逊的 S3 SDK 工作并浪费开发人员的时间。我在想也许我们必须手动劫持授权 header ,但这超出了我的专业知识范围。任何帮助将不胜感激。
最佳答案
所以我要晚点发帖说我使用的是 laravel 5.1,你必须在配置时选择是使用 AWS 还是 GCS,因为你无法安装两个版本的 aws php 客户端(这将您对 flysystem 的选择限制为 v2 或 v3。GCS 暂时需要 v2,而 laravel 中的 s3 实现需要 v3。我花了小时试图让 v3 到与 GCS 一起工作,但身份验证 header 不同,所以我没有打扰。
您必须提供自己的提供商,但设置起来并不难。只需在 app/Providers
中创建 GcsAppsServiceProvider.php<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Storage;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v2\AwsS3Adapter;
use League\Flysystem\Filesystem;
class GcsAppsServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
Storage::extend('gcs', function( $app, $config )
{
$client = S3Client::factory([
'key' => $config['key'],
'secret' => $config['secret'],
'base_url' => $config['base_url'],
]);
return new Filesystem(new AwsS3Adapter($client, $config['bucket']));
});
}
}
基本上在您的配置中,您只是在 filesystem.php 中复制 s3 配置并更改区域 -> base_url。您还可以自由地将默认值和云更改为 gcs 以支持谷歌云存储。
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY', 'your-key'),
'secret' => env('AWS_SECRET', 'your-secret'),
'region' => env('AWS_REGION','your-region'),
'bucket' => env('AWS_BUCKET','your-bucket'),
],
'gcs' => [
'driver' => 'gcs',
'key' => env('GCS_KEY', 'your-key'),
'secret' => env('GCS_SECRET', 'your-secret'),
'base_url' => env('GCS_BASE_URL','your-base-url'),
'bucket' => env('GCS_BUCKET','your-bucket'),
],
最后但同样重要的是,您还需要将提供者添加到 app.php 中的提供者列表中
'providers' => [
...
App\Providers\GcsAppsServiceProvider::class,
],
AWS S3 适配器还提到 GCS supports it in their documentation .
关于google-app-engine - 为什么 Google Storage API 不能与 Amazon SDK v3 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30790265/
嗨,当尝试将图像上传到 firebase 存储时,我正在使用 firebase 文档,但是出现此错误。 在范围内找不到“存储” let storage = Storage.storage() le
我最近在使用 Firebase 存储时遇到了一些问题。 当我们尝试访问刚刚上传的文件时,浏览器中出现此错误消息 { "error": { "code": 400,
这些是在不同版本的 NuGet 包之间迁移的重要指南: https://github.com/Azure/azure-sdk-for-net/blob/Azure.Storage.Blobs_12.6
警告: Warning: Can't resolve all parameters for Storage in /Users/zzm/Desktop/minan/node_modules/@ioni
我在圆形立方体中收到此错误(“连接到存储服务器失败”)行。我已经检查了所有内容,配置和数据库用户名密码,服务器详细信息都是干净的。谁能告诉我可能是什么问题。这里我给出了整个配置文件。
我希望能够限制容器的大小,但是使用默认的存储驱动程序aufs(对于Ubuntu 14.04),当我尝试使用--storage-opt参数时出现错误 $ docker create -it --name
我希望能够支持对使用 Google Cloud Storage 托管的静态 Assets 进行 Brotli 和 Gzip 编码。为此,我想在将文件上传为 之前对其进行编码, .gz和 .br .问
场景 我有几个由 Google Cloud Storage object.finalize 事件触发的 Google Cloud Functions。为此,我使用两个存储桶并使用“同步选项:覆盖目标位
我在 Google Cloud Storage 中有一个存储桶和一个网站。人们目前可以通过网站上传到存储桶(使用 Google 身份验证)。 但是,我需要设置它以便任何人都可以查看上传的文件(并且不能
如果文件被放入 Google Cloud 存储并公开,但该文件的网址在另一个网页上不存在,那么 Google 是否会在其搜索结果中将其编入索引?有人知道吗? 最佳答案 Google 的搜索索引独立于其
截至今天早上,我无法访问我的存储桶。 当我在导航上选择 Google Cloud Storage 选项卡时,一切都按预期加载,但不是显示我的两个存储桶,而是显示一个警告栏说: We were unab
我想弄清楚是否可以在 Windows 平台上使用 gsutil 的 cp 命令将文件上传到 Google Cloud Storage。我的本地计算机上有 6 个文件夹,每天都会向其中添加新的 pdf
我最近开始使用 Google Cloud Storage。最初我在安装 Cloud SDK 时创建了一个虚拟项目。现在我正在做另一个项目。 gsutil 仍然指向我以前的项目。我如何使它指向我的新项目
我目前正在这样做,但它非常慢,因为我的存储桶中有几 TB 的数据: gsutil du -sh gs://my-bucket-1/ 对于子文件夹也是如此: gsutil du -sh gs://my-
这可能看起来很天真,我知道我们可以在 blob 中创建文件夹,并且这些文件夹仍然存储在容器中。我们仍然可以对这些“blob 中包含的文件夹”执行通常对文件存储中的文件夹执行的所有操作。 我们仍然可以像
将文件上传到 Google Cloud Storage 时,有一个自定义数据字段元数据。 Google's example相当短: var metadata = { contentType: 'a
这可能看起来很天真,我知道我们可以在 blob 中创建文件夹,并且这些文件夹仍然存储在容器中。我们仍然可以对这些“blob 中包含的文件夹”执行通常对文件存储中的文件夹执行的所有操作。 我们仍然可以像
我有一个包含超过 2 万个文件名的 Google Storage 存储桶。有没有办法在短时间内列出存储桶中的所有文件名? 最佳答案 这取决于您所说的“短”是什么意思,但是: 您可以做的一件事来加快列出
有谁知道如果文件不存在,您是否需要为 Google Cloud Storage 中的文件请求付费?换句话说,有人访问您存储桶中不存在的文件是否计入您的请求?还是仅适用于存在的文件? 最佳答案 客户无需
在每一分钟结束时,我的代码总共会上传 20 到 40 个文件(从多台机器上并行上传大约 5 个文件,直到全部上传完毕)到 Google Cloud Storage。我经常收到 429 - Too Ma
我是一名优秀的程序员,十分优秀!