Forum Discussion

N_P's avatar
N_P
Occasional Contributor
2 years ago

SignatureDoesnotMatch error when uploading file to google bucket

Hi Team,

 

I am trying to upload pdf file to google bucket but getting error as below

 

Endpoint: https://storage.googleapis.com/pnsm-evq/Documents/{ID}/2022-11-17T14%3A14%3A20Z_README.pdf?X-Goog-Algorithm=xxxxx&X-Goog-Credential=xxxxxxxxxxxxxxxxxxxxxxxxx&X-Goog-Date=20221117T141420Z&X-Goog-Expires=29&X-Goog-Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&X-Goog-SignedHeaders=content-type%3Bhost

 

Code: SignatureDoesNotMatch

Message: The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

StringToSign: GOOG4-RSA-SHA256 20221117T141420Z 20221117/auto/storage/goog4_request 31acd2cb4f0901569693fd5a1d894932b20535f4065f67b7a9f21369a0059ae7

CononicalRequest: XXXXXXXXXXXXXXXXXXXXXXXXXXXXx

 

Any request would be highly appreciated.

 

Thanks and Regards,

Nishant Prakash

  • Hey N_P 

     

     

    Looking at the error response and the endpoint you provide I'd suggest you're not providing the correct headers (the "Endpoint" URL you supply launches 

     

    I have a look at the screenshot you embedded and it appears that you have lots of x-goog-% query parms. 

    Should these query parms actually be header parms on the request rather than query parms?

     

    I did try taking a look to find the headers needed on a google bucket upload, but I couldn't find anything that wasnt contradictory (I suspect the headers have changed over time perhaps).

     

    Anyway - if you DO know the correct URI pattern (including query parms) along with the correct header parms, I'd suggest you just need to update the relevant query parms to 'header' in your screenshot.

     

    Worst case - if you are unsure on the headers/query parm combination, you could manually upload a file via your browser (ensuring to proxy the request via Fiddler, which is an HTTP/HTTPS traffic sniffer) - Fiddler will then show you the correct headers/query parms needed to upload a file and then you can do it from within ReadyAPI by emulating the same query/header parms on the request.

     

    Sorry I can't be of more help - but without knowing the correct URI pattern and required headers - this is my best guess!

     

    Cheers,

     

    Rich

     

  • richie's avatar
    richie
    Community Hero

    Hey N_P 

     

     

    Looking at the error response and the endpoint you provide I'd suggest you're not providing the correct headers (the "Endpoint" URL you supply launches 

     

    I have a look at the screenshot you embedded and it appears that you have lots of x-goog-% query parms. 

    Should these query parms actually be header parms on the request rather than query parms?

     

    I did try taking a look to find the headers needed on a google bucket upload, but I couldn't find anything that wasnt contradictory (I suspect the headers have changed over time perhaps).

     

    Anyway - if you DO know the correct URI pattern (including query parms) along with the correct header parms, I'd suggest you just need to update the relevant query parms to 'header' in your screenshot.

     

    Worst case - if you are unsure on the headers/query parm combination, you could manually upload a file via your browser (ensuring to proxy the request via Fiddler, which is an HTTP/HTTPS traffic sniffer) - Fiddler will then show you the correct headers/query parms needed to upload a file and then you can do it from within ReadyAPI by emulating the same query/header parms on the request.

     

    Sorry I can't be of more help - but without knowing the correct URI pattern and required headers - this is my best guess!

     

    Cheers,

     

    Rich

     

    • N_P's avatar
      N_P
      Occasional Contributor

      Hi richie ,

       

      Thanks a Lot for the reply.

       

      The URI is correct. Its a signedURL which is getting generated in response of previous API.

      This signed URL I am using to upload file to my bucket.

       

       ==> I have a look at the screenshot you embedded and it appears that you have lots of x-goog-% query parms. Should these query parms actually be header parms on the request rather than query parms? - Those x-goog-% will be in the query params only. 

       

      I have tried adding the Content-type as application/pdf also, but the error message is same.

       

      Attaching the screenshot of the same.

       

      Seems the URL is getting encoded after sending the request. 

       

      Second Approach:

       

      I am trying to achieve the same using the groovy Script.

      Where I am stuck how to attach PDF file in the PUT request using groovy.

      I am attaching my script code.

      Kindly have a look and let me know how I can attach any PDF file in the request body.

       

      Help would be appreciated.

       

      Thanks and Regards,

      N_P

       

       

       

      • richie's avatar
        richie
        Community Hero

        Hey N_P 

         

        I can't spend too long thinking about this today cos I have to revise for a new job interview today (but I promise I will come back to this tomorrow), but in the meantime I have a couple of thoughts.

         

        How are you attaching/embedding the pdf?  If you are attaching/embedding - you can't use application/pdf as the ContentType header - you'll need to use something like x-www-form-urlencoded or multipart/form-data or application/multipart/mixed.

         

        Have a look here -->  https://support.smartbear.com/readyapi/docs/requests/attachment/rest.html  <-- this provides some help/background info on attaching/embedding file content into a REST request.

         

        Also - I'm not understanding something - you mention the "URL is getting encoded on the second request" - I can see from your screenshot in the end of the URI you have URL encoding - but are you saying that if you submit the request initially, the URL encoding isn't happening?  URL encoding (not payload URL encoding - then you have to alter the ContentType header) happens by default in ReadyAPI!, unless you disable it yourself - there's a checkbox in the advanced options in the 'Request' section of your API. 

        SO! - would you mind explaining what you mean by it encodes the second request please?  I'm obviously not understanding something here! 🙂

         

        Oh yeah - I can see youre base64 encoding the pdf in your groovy script.  How was you handling the base64 encode when you tried using the native ReadyAPI functionality rather than using groovy script?

         

        ok - that's all I got in my head right now, but I will be back tomorrow

         

         

         

        Cheers,

         

        Rich

         

  • N_P's avatar
    N_P
    Occasional Contributor

    Hi richie ,

     

    Something is better than nothing, when you learn anything new.

     

    Your suggestion helped, and now I am able to hit the signed URL will 200 success response code.

     

    I made a change in my setting as per your suggestion that enables - URL contains encoded endpoints, do not try to encode. and it worked fine for me.

     

    But on the same point when I am trying to upload PDF file, it is not getting uploaded. I tried multiple ways, but not able to so. Any suggestion on this can also help me to achieve my desired result.

     

    I have uploaded the image file. Kindly have a look.

     

    Thanks and Regards,

    Nishant Prakash