Signing key was not provided and could not be derived on google precondition

戏子无情 提交于 2021-02-11 12:46:13

问题


so i am trying to generate a signed url for uploading a file on Google cloud platform using java springboot following the instructions provided on ..

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

i am having a security key with all the permission. The problem is i am able to generate a signed url for uploading object with the documentation .when i am runnig the code in local . but in production I am getting the issue

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]

so i searched on google and according to one resource https://www.codota.com/code/java/methods/com.google.cloud.storage.Storage/signUrl changed my code to

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();
        }

and when i am trying to upload from the new url is giving me

<?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

来源:https://stackoverflow.com/questions/63355556/signing-key-was-not-provided-and-could-not-be-derived-on-google-precondition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!