“每次上传或下载结束时,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();
}
是否需要执行校验和?我应该手动执行吗?
最佳答案
我们建议计算所有上传和下载的校验和,并验证您计算的校验和是否与服务的校验和匹配。这样做可以保护您免受客户端或客户端库错误的影响,这些错误可能会损坏传入/传出云的数据。
我将打开一个错误来更新该示例代码,包括计算校验和。
关于java - Google 的 'gsutil cp' 命令对传输的文件运行校验和。 Google 的 java 存储 API 是否也做同样的事情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39578154/