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

时间:2020-08-11 09:39:22

标签: java google-cloud-platform

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

上提供的说明,使用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

0 个答案:

没有答案