【问题标题】:Batch request with Google Storage Json Api (JAVA)使用 Google Storage Json Api (JAVA) 的批量请求
【发布时间】:2012-11-19 02:50:07
【问题描述】:

我正在尝试在来自 appengine (JAVA) 的一批请求中设置多个 ACL。我不确定发出请求的 URL 应该是什么。 documentation 声明“/batch”。是否还有可用的示例? AFAIK 无法从 API 资源管理器进行测试。

【问题讨论】:

标签: google-app-engine google-cloud-storage


【解决方案1】:

使用 google-api-java-client 库和存储 JSON API,批处理请求将如下所示:

// Create the Storage service object
Storage storage = new Storage(httpTransport, jsonFactory, credential);

// Create a new batch request
BatchRequest batch = storage.batch();

// Add some requests to the batch request
storage.objectAccessControls().insert("bucket-name", "object-key1",
    new ObjectAccessControl().setEntity("user-123423423").setRole("READER"))
    .queue(batch, callback);
storage.objectAccessControls().insert("bucket-name", "object-key2",
    new ObjectAccessControl().setEntity("user-guy@example.com").setRole("READER"))
    .queue(batch, callback);
storage.objectAccessControls().insert("bucket-name", "object-key3",
    new ObjectAccessControl().setEntity("group-foo@googlegroups.com").setRole("OWNER"))
    .queue(batch, callback);

// Execute the batch request. The individual callbacks will be called when requests finish.
batch.execute();

请注意,您目前必须请求访问 Storage JSON API,因为它处于有限的测试阶段。

相关 API 文档在这里:https://developers.google.com/storage/docs/json_api/v1/objectAccessControls

Java 客户端库中有关批处理请求的文档:https://code.google.com/p/google-api-java-client/wiki/Batch

用于存储 Java 客户端库的 JavaDoc:https://google-api-client-libraries.appspot.com/documentation/storage/v1beta1/java/latest/index.html

【讨论】:

  • 一个警告:如果您使用相同的资源(存储桶或对象)并对它发出多个批处理 ACL 编辑(插入/更新)请求,您将导致对该资源的争用,因为批处理请求所有并行发生。如果您需要这样做,在我们可以解决该问题之前,您可以编辑资源本身的 acl 属性,这是这些 ACL 的列表。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多