johnnyhalife / waz-storage

A simple implementation of Windows Azure Storage API for Ruby, inspired by the S3 gems and self experience of dealing with queues. The major goal of the whole gem is to enable ruby developers [like me =)] to leverage Windows Azure Storage features and have another option for cloud storage.
http://waz-storage.heroku.com
MIT License
40 stars 21 forks source link

blob upload fails with 400 when use_sas_auth_only=true #41

Open grahamkenville opened 9 years ago

grahamkenville commented 9 years ago

I'm writing a script to upload largish files. When I specify use_sas_auth_only it fails with a 400 error (see below). This is with waz-storage (1.3.6).

Thanks!


#!/usr/bin/env ruby

# gem install waz-storage --source http://gemcutter.org
require 'waz-blobs'

file_to_upload = "test.txt"

# Works:
# WAZ::Storage::Base.establish_connection!(:account_name => 'test', :access_key => 'key-goes-here')

# Doesn't work:
WAZ::Storage::Base.establish_connection!(:account_name => 'drbackup',
                                         :use_sas_auth_only => true,
                                         :sharedaccesssignature => 'key-goes-here'
                                         )

container = WAZ::Blobs::Container.new(:name=>'rubytest')

fd = IO.sysopen(file_to_upload, "r")
stream = IO.new(fd)

puts "Uploading"
container.upload(file_to_upload,
                 stream,
                 'application/octet-stream'
                 ) 

Script output:

Uploading
RestClient::BadRequest: 400 Bad Request
         return! at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74
  process_result at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/rest-client-1.8.0/lib/restclient/request.rb:495
        transmit at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/rest-client-1.8.0/lib/restclient/request.rb:421
           start at /usr/local/lib/jruby-1.7.17/lib/ruby/1.9/net/http.rb:746
        transmit at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/rest-client-1.8.0/lib/restclient/request.rb:413
         execute at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/rest-client-1.8.0/lib/restclient/request.rb:176
         execute at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/waz-storage-1.3.6/lib/waz/storage/core_service.rb:124
       put_block at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/waz-storage-1.3.6/lib/waz/blobs/service.rb:158
          upload at /usr/local/lib/jruby-1.7.17/lib/ruby/gems/shared/gems/waz-storage-1.3.6/lib/waz/blobs/container.rb:144
          (root) at ./test.rb:26

Wireshark trace with a text file upload:

PUT /rubytest/test.txt?key-goes-here HTTP/1.1
Accept: */*; q=0.5, application/xml
Accept-Encoding: gzip, deflate
Content-Type: application/octet-stream
X-Ms-Date: Tue, 25 Aug 2015 20:55:22 GMT
Content-Length: 53
User-Agent: Ruby
Host: test.blob.core.windows.net

HTTP/1.1 400 An HTTP header that's mandatory for this request is not specified.
Content-Length: 295
Content-Type: application/xml
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 1a58eb8b-0001-003a-7b78-df52be000000
x-ms-version: 2014-02-14
Date: Tue, 25 Aug 2015 20:55:21 GMT

...<?xml version="1.0" encoding="utf-8"?><Error><Code>MissingRequiredHeader</Code><Message>An HTTP header that's mandatory for this request is not specified.
RequestId:1a58eb8b-0001-003a-7b78-df52be000000
Time:2015-08-25T20:55:22.5160429Z</Message><HeaderName>x-ms-blob-type</HeaderName></Error>-----------
this is the test upload file
-----------