有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在春季从云存储中生成URL文件而无需持续时间

下面是我从云存储生成的url源代码

public String generateImageUrl(String fileName, Integer duration, String folderName) throws IOException {

    Credentials credentials = GoogleCredentials.fromStream(new ClassPathResource(STORAGE_FILE_NAME).getInputStream());
    Storage storage = StorageOptions.newBuilder().setCredentials(credentials).setProjectId(PROJECT_ID).build().getService();
    Bucket bucket = storage.get(BUCKET_NAME, Storage.BucketGetOption.fields(Storage.BucketField.values()));
    logger.info("Bucket name : " + bucket.getName());
    String fullImagePath = folderName + "/" + fileName;
    BlobId imgId = BlobId.of(BUCKET_NAME, fullImagePath);

        if(null!=imgId) {
            Blob blob = storage.get(imgId);
            if(null!=blob && blob.exists()) {
                URL signedUrl = storage.signUrl(blob, duration, TimeUnit.MINUTES);
                String imageUrl = signedUrl.toExternalForm();
                logger.info("Generated image url : " + imageUrl);
                return imageUrl;
            }
        }

        return null;
}

But the generated url has an access duration

如何实现它,以便不提供访问持续时间


共 (1) 个答案

  1. # 1 楼答案

    无法创建没有访问持续时间的签名url

    云存储Signed Urls的最大过期延迟为7天

    You specify an expiration time when you create the signed URL. Anyone who knows the URL can access the resource until the expiration time for the URL is reached or the key used to sign the URL is rotated.

    节选自Java client library docs

    Note that V4 Signed URLs can't have an expiration longer than 7 days.

    您还可以查看更多详细信息here