GSUTIL Signed PUT URL for Google Cloud Storage Fails

I want site users to be able to upload files to google cloud storage without using web application resources, so signed URLs look like a way.

When the user selects the file to download jquery , it sends a GET request to django for the signed URL. The URL is created using the gsutil signurl . django then returns the signed URL to the template and sends a jquery PUT request with the signed URL.

However:

  • PUT request does not work with 'SignatureDoesNotMatch'.
  • GET requests for storage objects operate using this method.

Are headers required to be sent with a PUT request required?

gsutil command (assuming the user has selected the file 'map.html') ...

 gsutil signurl -p notasecret -m PUT -d 10m /path/to/.p12 gs://bucket_name/map.html 

jquery put code ...

  $.ajax( { url: g_url, type: 'PUT', crossDomain: true, success: console.log('success'), error: function(XMLHttpRequest, textStatus, errorThrown){ alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText); }, data: file, } ); 

g_url looks like ...

 https://storage.googleapis.com/bucket_name/map.html?GoogleAccessId=__retracted__&Expires=1408889274&Signature=rDJAZQG4MIyMupy0M8HJ17r8rkEJcAbYSWpcq084SdzRh%2BnZavTfuWl4Q%2F6ytkSkN2c2%2B4b4pPRF5eWOEOL1InRxlB5pEBedPFZPpgDrRvR9tFybtH%2BkesKLhIZ3WjJ0utzAwhl%2BgAlQY6ulvO0Djib20zcG5fkHOigpRf1xBUk%3D 
+5
source share
1 answer

Turns out my problem is with CORS. To get this to work on Django 1.6 , I had to do the following:

With the launch of these PUT and DELETE queries. The only problem I encountered was incompatible content headers. Therefore, you need to set your content type in the signed URL and before sending the request.

The gsutil command will look like

 gsutil signurl -p notasecret -m PUT -d 10m -c 'multipart/formdata; charset=UTF-8' /path/to/.p12 gs://bucket_name/map.html 

add beforeSend to jquery query

 beforeSend: function (request){ request.setRequestHeader("Content-Type", 'multipart/formdata; charset=UTF-8') ;}, 
+1
source

Source: https://habr.com/ru/post/1201031/


All Articles