2012-11-30 39 views
1

我试图在appengine(JAVA)的一个批处理请求中设置多个ACL。我不确定提出请求的网址应该是什么。 documentation表示“/批”。有没有更多的例子可用? AFAIK这是不可能从API浏览器进行测试的。使用Google Storage Json Api(JAVA)的批量请求

+0

你说得对,API浏览器https://developers.google.com/storage/docs/json_api/v1/objectAccessControls

关于Java客户端库批量请求文件目前不支持批量请求,这使得尝试更难一些。我建议将Java客户端库用于支持批量请求的云存储。 https://code.google.com/p/google-api-java-client/wiki/Batch + https://code.google.com/p/google-api-java-client/wiki/APIs#Cloud_Storage_API –

回答

6

使用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("[email protected]").setRole("READER")) 
    .queue(batch, callback); 
storage.objectAccessControls().insert("bucket-name", "object-key3", 
    new ObjectAccessControl().setEntity("[email protected]").setRole("OWNER")) 
    .queue(batch, callback); 

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

请注意,你必须在一瞬间请求访问存储JSON API,因为它是在有限测试版。

相关的API文档是在这里:https://code.google.com/p/google-api-java-client/wiki/Batch

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

+1

一个警告:如果您使用相同的资源(存储桶或对象)并针对它进行多个批量ACL编辑(插入/更新)请求,则会导致该资源发生争用,因为批量请求全部并行发生。如果您需要这样做,直到我们可以解决该问题为止,您可以编辑资源本身的acl属性,这是这些ACL的列表。 –

相关问题