0

I have made a connection with Google Storage using gem 'google-cloud-storage'. Repo for that is https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-storage.

The example of the signed_url method I couldn't manage to find it only in one example in the repo, here, line 916: https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/google-cloud-storage/lib/google/cloud/storage/bucket.rb

I managed to get a signed URL for method GET for a specific file, but when I try to do a PUT on the signed_url for a file it gives me a response body like so:

<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

application/x-www-form-urlencoded
1523909074
/bucket_name/logo1</StringToSign>
</Error>

Sample code of PUT (NOT WORKING):

require 'google/cloud/storage'
storage = Google::Cloud::Storage.new(
    project_id: 'projectId',
    credentials: './config/keyfile.json'
)

bucket = storage.bucket 'bucket_name'
signed_url = bucket.signed_url 'logo1.png',
                   method: 'PUT',
                   content_type: 'image/png',
                   expires: 300 # 5 minutes from now

I tried doing with and without content_type. Also I tried content_type: '*' or '**' or 'image/*' or ''. I tried the PUT request in Postman and in an Angular app using a primeng upload component. Need a little help. Thanks.

  • I had followed this recently http://andrewvos.com/uploading-files-directly-to-google-cloud-storage-from-client-side-javascript it worked. – Nithin Apr 17 '18 at 10:37
  • https://github.com/imnithin/direct_upload-gcs I created a gem, not tested. – Nithin Apr 17 '18 at 10:38
  • @Nithin I saw and I tried that example, but It didn't worked for me because I didn't knew exactly what RSA Pkey to give. Also That's not the best practice in my opinion. Google already provides everything for you. – Claudiu Lazăr Apr 17 '18 at 10:53
  • Thanks for the gem, but I do not want to use a gem that is not tested or it is not proven to be stable. I want to go in production with this project. – Claudiu Lazăr Apr 17 '18 at 10:57

1 Answers1

1

Everything was good. I forgot to add Content-Type in the request's header. I thought it is implied in the signed url, but no.