BlobId blobId = BlobId.of(bucketName, filename);
Blob blob = storage.get(blobId);
boolean isFileDeleted = storage.delete(blobId);
这里我得到了 null
对于有文件名空间的 blob。在我的存储桶中,结构是 sample-bucket/Archive 2copy.zip
。请注意文件名中的空格。
有人可以帮我吗?
最佳答案
我正在使用 Google Java Api - StorageExample.java并能够删除他名字中带有空格的 Blob 。他们正在按 id 删除 blob。
private static class DeleteAction extends BlobsAction {
@Override
public void run(Storage storage, BlobId... blobIds) {
// use batch operation
List<Boolean> deleteResults = storage.delete(blobIds);
int index = 0;
for (Boolean deleted : deleteResults) {
if (deleted) {
// request order is maintained
System.out.printf("Blob %s was deleted%n", blobIds[index]);
}
index++;
}
}
}
Expected: <bucket> <path>+
target/appassembler/bin/StorageExample delete bucket-name 'test file'
Blob BlobId{bucket=bucket-name, name=test file, generation=null} was deleted
关于java - 无法使用 java 删除 gcp 存储中文件名中有空格的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60862400/