2012-11-30 40 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的列表。 –

相關問題