未提供签名密钥,无法在Google前提条件下派生

问题描述

因此,我正在尝试按照..

上提供的说明,使用java springboot生成用于在Google云平台上上传文件的签名URL。

https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-code-sample

我拥有所有权限的安全密钥。 问题是当我在本地运行代码时,我能够生成用于上传对象的签名URL。 但是在生产中我遇到了问题

Caused by: java.lang.IllegalStateException: Signing key was not provided and Could not be derived
    at com.google.common.base.Preconditions.checkState(Preconditions.java:511) ~[guava-29.0-android.jar!/:na]
    at com.google.cloud.storage.StorageImpl.signUrl(StorageImpl.java:655) ~[google-cloud-storage-1.108.0.jar!/:1.108.0]

因此我根据一种资源在Google上进行了搜索 https://www.codota.com/code/java/methods/com.google.cloud.storage.Storage/signUrl 将我的代码更改为

public static URL generateV4PutObjectSignedUrl(String projectId,String bucketName,String objectName)  {
        Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
        BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName,objectName)).build();
        Map<String,String> extensionHeaders = new HashMap<>();
        extensionHeaders.put("Content-Type","application/json");
        URL url = null;
        try {
            url = storage.signUrl(
                    blobInfo,15,TimeUnit.MINUTES,Storage.SignUrlOption.httpMethod(HttpMethod.PUT),Storage.SignUrlOption.withExtHeaders(extensionHeaders),Storage.SignUrlOption.signWith(ServiceAccountCredentials.fromStream(new FileInputStream(GOOGLE_API_CREDENTIALS))));
        } catch (IOException e) {
            e.printstacktrace();
        }

当我尝试从新网址上传时,给了我

<?xml version='1.0' encoding='UTF-8'?><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message><StringToSign>PUT

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)