分段上传 Google 存储空间

multi-part upload Google Storage

我正在尝试将多部分上传到 Google 存储,但令我惊讶的是它似乎并不简单(我找不到 java 示例)。

我发现的唯一提及是在 XML API https://cloud.google.com/storage/docs/multipart-uploads

还发现了一些围绕撰写的讨论 API StorageExample.java#L446 mentioned here google-cloud-java issues 1440

对如何进行分段上传有什么建议吗?

目前Java Cloud Storage 中的分段上传客户端库不可用。您可以在此 link. As mentioned by John Hanley, the next best thing you can do is, do a parallel composite upload with gsutil (CLI), JSON and XML support/ resumable upload 和 Java 库中提出相同的功能请求。

在并行撰写中,并行写入可以通过使用 JSON 或 XML API 用于 Google 云存储来完成。具体来说,您将并行写入许多较小的对象,然后(一旦所有这些对象都已写入)调用 Compose 请求将它们组合成一个较大的对象。

如果您使用的是 JSON API 撰写文档位于:https://cloud.google.com/storage/docs/json_api/v1/objects/compose

如果您使用的是 XML API,撰写文档位于:https://cloud.google.com/storage/docs/reference-methods#putobject(请参阅撰写查询参数)。

Kolban 还提供了一份有趣的文档 link,您可以尝试并研究它。另外我想提一下,如果您使用 Google Drive API(v3),您可以在 Java 中进行多部分上传。这是 uploadType=multipart 的 code example where we use the files.create 方法。

我根据@Koblan 的建议得到了 multi-part 上传。 (详情请查看 blog post

这就是我创建 S3 客户端并将其指向 Google 存储

的方式
def createClient(accessKey: String, secretKey: String, region: String = "us"): AmazonS3 = {
    val endpointConfig = new EndpointConfiguration("https://storage.googleapis.com", region)
    val credentials = new BasicAWSCredentials(accessKey, secretKey)
    val credentialsProvider = new AWSStaticCredentialsProvider(credentials)
    val clientConfig = new ClientConfiguration()
    clientConfig.setUseGzip(true)
    clientConfig.setMaxConnections(200)
    clientConfig.setMaxErrorRetry(1)
    val clientBuilder = AmazonS3ClientBuilder.standard()
    clientBuilder.setEndpointConfiguration(endpointConfig)
    clientBuilder.withCredentials(credentialsProvider)
    clientBuilder.withClientConfiguration(clientConfig)
    clientBuilder.build()
  }

因为我正在从前端上传(在我使用 AmazonS3 客户端为每个部分生成签名 URL 之后)我需要启用 CORS。

为了测试,我暂时启用了所有功能

$ gsutil cors get gs://bucket
$ echo '[{"origin": ["*"],"responseHeader": ["Content-Type", "ETag"],"method": ["GET", "HEAD", "PUT", "DELETE", "PATCH"],"maxAgeSeconds": 3600}]' > cors-config.json
$ gsutil cors set cors-config.json gs://bucket

https://cloud.google.com/storage/docs/configuring-cors#gsutil_1