2016-09-19 61 views
0

documentation on gsutilGoogle的'gsutil cp'命令對傳輸的文件運行校驗和。 Google的Java存儲API是否也一樣?

「每上傳年底或下載gsutil cp指令驗證了它計算源文件的校驗/對象的服務計算校驗和匹配。如果校驗和不匹配,gsutil會將刪除損壞的對象並打印警告消息。「

而且這裏的一些sample code使用他們的Java存儲API:

public static void uploadFile(String name, String contentType, File file, String bucketName) 
    throws IOException, GeneralSecurityException { 
    InputStreamContent contentStream = new InputStreamContent(
      contentType, new FileInputStream(file)); 
    // Setting the length improves upload performance 
    contentStream.setLength(file.length()); 
    StorageObject objectMetadata = new StorageObject() 
     // Set the destination object name 
     .setName(name) 
     // Set the access control list to publicly read-only 
     .setAcl(Arrays.asList(
      new ObjectAccessControl().setEntity("allUsers").setRole("READER"))); 

    // Do the insert 
    Storage client = StorageFactory.getService(); 
    Storage.Objects.Insert insertRequest = client.objects().insert(
      bucketName, objectMetadata, contentStream); 

    insertRequest.execute(); 
} 

是進行必要的校驗?我應該手動做嗎?

回答

3

我們建議您對所有上傳和下載進行計算校驗和,並驗證您計算的校驗和與服務的校驗和是否相符。這樣做可以防止客戶端或客戶端的庫錯誤,這些錯誤可能會破壞雲端/從雲端的數據。

我打開一個錯誤來更新示例代碼,以包含計算校驗和。

相關問題