4

I'm trying to upload an object to the Google cloud storage, using a signed url. I'm generating the url, using a JAVA method, as follows (with the help of this link):

public String generatePutObjectSignedUrl(String bucketName, String objectName, String contentType) throws GenericAttachmentException {
        if (!bucketExists(bucketName)) {
            createBucket(bucketName);
        }
        // Define resource
        BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build();

        // Generate signed URL
        Map<String, String> extensionHeaders = new HashMap<>();
        extensionHeaders.put("Content-Type", contentType);

        return String.valueOf(storage.signUrl(
                blobInfo,
                15,
                TimeUnit.MINUTES,
                SignUrlOption.httpMethod(HttpMethod.PUT),
                SignUrlOption.withExtHeaders(extensionHeaders),
                SignUrlOption.withV4Signature()));

    }

I'm also getting an upload url, as follows:

https://storage.googleapis.com/bucket/43fb114d-973e-4157-8a3d-0d479aa5b255/1553.pdf?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=storage-dev%40project-name-229712.iam.gserviceaccount.com%2F20200622%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20200622T181856Z&X-Goog-Expires=900&X-Goog-SignedHeaders=content-type%3Bhost&X-Goog-Signature=27de4c5f8f669ead91cdf2a3cf91485ac272be5357420dc40d75a534834ed300d19098f857c638558624b4500762820002fa99071f35723146c4afca01d5b77f56c90fa63b53598b887d71ef7a49b2bb389ce70bcee11db9f5cff6f6164e9821753ae82651379138b12b46c82c0fee3d8898b45a4b06fd80925a501d036289093fcb94226cfdecd285991ea2a215577321ffc1c1d5f30bfe0e83c1b876351e87240cf17eb940fdb91d813cb8b7988ce09f71e51464728ac58e3d8fdd8d3bb5a279791d87069fc8d3719ad2080886ff931f00e3691fbe85df3f503ab9175da2d5b7d65c3d3412a3f8f9446164682e17dcf64942fa6d2c30a2e173438e186221d5

But, when I try to upload an object, using HTTP PUT on the above URL, using POSTMAN, I get the following error:

<?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>GOOG4-RSA-SHA256
20200622T181856Z
20200622/auto/storage/goog4_request
086bc1e8dfe17975d9c67a59edcaf003a26631a2451b82a370b0bbaf0a8003be</StringToSign>
    <CanonicalRequest>PUT
/bucket/43fb114d-973e-4157-8a3d-0d479aa5b255/1553.pdf
X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;X-Goog-Credential=storage-dev%40project-name-229712.iam.gserviceaccount.com%2F20200622%2Fauto%2Fstorage%2Fgoog4_request&amp;X-Goog-Date=20200622T181856Z&amp;X-Goog-Expires=900&amp;X-Goog-SignedHeaders=content-type%3Bhost
content-type:multipart/form-data; boundary=--------------------------707205682373848354360690
host:storage.googleapis.com

content-type;host
UNSIGNED-PAYLOAD</CanonicalRequest>
</Error>

It's been a real tough nut to crack. Would really appreciate some help.

Roshan Upreti
  • 1,782
  • 3
  • 21
  • 34
  • Maybe [this](https://cloud.google.com/storage/docs/access-control/signed-urls#signing-resumable) could help you – Chris32 Jun 22 '20 at 20:58

0 Answers0