所以从GCS存储桶删除文件时出现问题,我使用Java创建文件,代码如下:
public void upload(String projectId, String bucketName, String filePath, String fileName)
throws IOException, URISyntaxException {
File f = new File(gcsCredDirectory+gcsCredFileName);
if (!f.exists()) {
f.mkdirs();
}
try(InputStream is = new FileInputStream(f)) {
StorageOptions storageOptions = StorageOptions.newBuilder()
.setProjectId(projectId).setCredentials(fromStream(is)).build();
Storage storage = storageOptions.getService();
BlobId blobId = BlobId.of(bucketName, fileName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
Blob result = storage.create(blobInfo, Files.readAllBytes(Paths.get(filePath)));
URL url = storage.signUrl(blobInfo, MAX_EXPIRED_DATE, TimeUnit.DAYS, SignUrlOption.withV4Signature());
} catch (Exception e) {
LOGGER.error("ERROR at GoogleCloudStorageServiceImpl.upload cause : ", e);
throw e;
}
}
创建的代码运行得很好,我得到了一个URL,可以下载我上传的文件,实际上可以下载该文件,但是在通过以下代码删除文件后:
public boolean delete(String projectId, String bucketName, String fileName) {
File f = new File(gcsCredDir+gcsCredFileName);
if (!f.exists()) {
f.mkdirs();
}
try(InputStream is = new FileInputStream(f)) {
StorageOptions storageOptions = StorageOptions.newBuilder()
.setProjectId(projectId)
.setCredentials(fromStream(is))
.build();
boolean result = storageOptions.getService().delete(bucketName, fileName);
LOGGER.info("Object " + fileName + " was deleted from " + bucketName);
return result;
} catch (Exception e) {
return false;
}
}
我能够看到日志Object + fileName + was deleted from + bucketName
,但是当我访问Url以下载文件时,我仍然可以下载它。我希望下载失败,因为文件已删除。
有什么建议吗?
谢谢
Cache-Control: max-age=0, no-cache
。您还可以指定public
或private.
publicmeans intermediate servers may cache the result (for faster response times).
private`,这意味着只有发出请求的客户端才应缓存响应,而不是中间服务器。为了尝试强制缓存丢弃数据,某些服务器接受PURGE
请求。这些可以通过curl -vv -X PURGE http(s)://example.com/path/to/resource