为什么 Google 云存储生成的上传 link 在上传成功后不会自行失效?
Why doesn't the upload link generated by the Google Cloud Storage invalidate itself after a successful upload?
我有一个 JAVA
方法可以获取 URL
,使用它我可以将对象上传到 Google 云存储中的存储桶。生成的URL
有效期为30秒(测试ok)
public String getSignedUploadLink(String bucketName, String objectName, String mimeType)
throws Exception {
try {
// check if bucket exists, and create one with notification, if it doesn't.
if (!bucketExists(bucketName)) {
createBucket(bucketName);
}
// Define Resource
BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build();
// Specify the object's content type.
Map<String, String> extensionHeaders = new HashMap<>();
extensionHeaders.put("Content-Type", mimeType);
//setting it to expire in 30 seconds
return storage.signUrl(
blobInfo,
30,
TimeUnit.SECONDS,
Storage.SignUrlOption.httpMethod(HttpMethod.PUT),
Storage.SignUrlOption.withExtHeaders(extensionHeaders),
Storage.SignUrlOption.withV4Signature()).toString();
} catch (Exception e) {
// Handle the caught exception
}
}
利用上述方法生成的link中的HTTP PUT
,我可以成功上传一个对象到Google云存储中。奇怪的是,如果我在到期前向同一个 URL
发送另一个 PUT
请求,我还可以上传另一个对象(当然具有相同的内容类型)。
它应该像这样工作吗?我的印象是,一旦使用上传 link 上传内容,它就会自行失效,无论有效期如何。难道是我在这里遗漏了什么吗?真的需要一些帮助。
是的,这就是它的工作方式。 documentation for signed URLs 中没有任何内容表明它们会因您创建时指定的时间以外的任何条件使自己失效。如果你说30秒好,那就是URL能用多长时间
我有一个 JAVA
方法可以获取 URL
,使用它我可以将对象上传到 Google 云存储中的存储桶。生成的URL
有效期为30秒(测试ok)
public String getSignedUploadLink(String bucketName, String objectName, String mimeType)
throws Exception {
try {
// check if bucket exists, and create one with notification, if it doesn't.
if (!bucketExists(bucketName)) {
createBucket(bucketName);
}
// Define Resource
BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build();
// Specify the object's content type.
Map<String, String> extensionHeaders = new HashMap<>();
extensionHeaders.put("Content-Type", mimeType);
//setting it to expire in 30 seconds
return storage.signUrl(
blobInfo,
30,
TimeUnit.SECONDS,
Storage.SignUrlOption.httpMethod(HttpMethod.PUT),
Storage.SignUrlOption.withExtHeaders(extensionHeaders),
Storage.SignUrlOption.withV4Signature()).toString();
} catch (Exception e) {
// Handle the caught exception
}
}
利用上述方法生成的link中的HTTP PUT
,我可以成功上传一个对象到Google云存储中。奇怪的是,如果我在到期前向同一个 URL
发送另一个 PUT
请求,我还可以上传另一个对象(当然具有相同的内容类型)。
它应该像这样工作吗?我的印象是,一旦使用上传 link 上传内容,它就会自行失效,无论有效期如何。难道是我在这里遗漏了什么吗?真的需要一些帮助。
是的,这就是它的工作方式。 documentation for signed URLs 中没有任何内容表明它们会因您创建时指定的时间以外的任何条件使自己失效。如果你说30秒好,那就是URL能用多长时间