Question: Ruby Error RangeError when post file

Question

Ruby Error RangeError when post file

Answers 0
Added at 2016-12-16 10:12
Tags
Question

I have an error "RangeError: RangeError" when I post a file throught my webservice.

  1. Sinatra version : sinatra (1.4.7)
  2. Ruby version : 2.3.1

See the error stack below:

RangeError: RangeError

    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/utils.rb:135:in `normalize_params'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/utils.rb:163:in `normalize_params'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/utils.rb:122:in `block in parse_nested_query'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/utils.rb:119:in `each'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/utils.rb:119:in `parse_nested_query'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/request.rb:371:in `parse_query'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/request.rb:215:in `POST'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:39:in `method_override_param'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:27:in `method_override'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/methodoverride.rb:15:in `call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/show_exceptions.rb:25:in `call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/thin-1.7.0/lib/thin/connection.rb:86:in `block in pre_process'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/thin-1.7.0/lib/thin/connection.rb:84:in `catch'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/thin-1.7.0/lib/thin/connection.rb:84:in `pre_process'
    /home/greg/.rvm/gems/ruby-2.3.1/gems/thin-1.7.0/lib/thin/connection.rb:50:in `block in process'

See the code used below:

require 'rubygems'
require 'sinatra'

set :bind, '127.0.0.1'
set :port, '4567'

post '/test' do

  body "Hello"
  status 202
  return

end

See the file posted below:

{
  "caller":"TEST",
  "c1": [ { "a" : ["b" ] } ],
  "c2": [ { "a" : ["b" ] } ],
  "c3": [ { "a" : ["b" ] } ],
  "c4": [ { "a" : ["b" ] } ],
  "c5": [ { "a" : ["b" ] } ],
  "c6": [ { "a" : ["b" ] } ],
  "c7": [ { "a" : ["b" ] } ],
  "c8": [ { "a" : ["b" ] } ],
  "c9": [ { "a" : ["b" ] } ],
  "c10": [ { "a" : ["b" ] } ],
  "c11": [ { "a" : ["b" ] } ],
  "c12": [ { "a" : ["b" ] } ],
  "c13": [ { "a" : ["b" ] } ],
  "c14": [ { "a" : ["b" ] } ],
  "c15": [ { "a" : ["b" ] } ],
  "c16": [ { "a" : ["b" ] } ],
  "c17": [ { "a" : ["b" ] } ],
  "c18": [ { "a" : ["b" ] } ],
  "c19": [ { "a" : ["b" ] } ],
  "c20": [ { "a" : ["b" ] } ],
  "c21": [ { "a" : ["b" ] } ],
  "c22": [ { "a" : ["b" ] } ],
  "c23": [ { "a" : ["b" ] } ],
  "c24": [ { "a" : ["b" ] } ],
  "c25": [ { "a" : ["b" ] } ]
}

See the command used to post my file below:

curl -v -H 'Accept: application/text' -X POST http://127.0.0.1:4567/test -d @$1

I think the problem is the JSON structure.

I try to post this JSON in PHP server, Python, and Java server and it works.

The limitation of the number of array is probably due to Sinatra framework. When I post a file with 49 arrays it work, but more than 50 it fail.

Thanks in advance.

Answers
Source Show
◀ Wstecz