Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Sinatra:在发送到API之前,通过MiniMagick压缩tempfile中的图像_Ruby_Api_Sinatra_Temporary Files_Minimagick - Fatal编程技术网

Ruby Sinatra:在发送到API之前,通过MiniMagick压缩tempfile中的图像

Ruby Sinatra:在发送到API之前,通过MiniMagick压缩tempfile中的图像,ruby,api,sinatra,temporary-files,minimagick,Ruby,Api,Sinatra,Temporary Files,Minimagick,在向API发送请求之前,我尝试使用以下代码压缩图像: require 'sinatra' require 'unirest' require 'mini_magick' require 'json' require 'open-uri' get '/' do File.read('public/views/index.erb') end post '/' do Unirest.timeout(5) image = MiniMagick::Image.open(p

在向API发送请求之前,我尝试使用以下代码压缩图像:

require 'sinatra'
require 'unirest'
require 'mini_magick'
require 'json'

require 'open-uri'

get '/' do

    File.read('public/views/index.erb')

end

post '/' do
    Unirest.timeout(5)
    image = MiniMagick::Image.open(params['user_image'][:tempfile])
    image.resize "600x400" 
    response = Unirest.post 'https://search.craftar.net/v1/search',
            parameters: {
                token: "703eb042371c49f0",
                image: image                                        
            }

    body = response.body

    url = body['results'][0]['item']['url']

  redirect url

end
当它运行以获得结果时,我得到以下错误:

ArgumentError at /
wrong number of arguments (1 for 0)

/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/tempfile.rb in open
  def open
/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/open-uri.rb in open
      name.open(*rest, &block)
/usr/local/lib/ruby/gems/2.2.0/gems/mini_magick-4.3.6/lib/mini_magick/image.rb in open
      Kernel.open(path_or_url, "rb") do |file|
server.rb in block in <main>
    image = MiniMagick::Image.open(params['user_image'][:tempfile])
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
          proc { |a,p| unbound_method.bind(a).call }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in compile!
          proc { |a,p| unbound_method.bind(a).call }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in []
            route_eval { block[*args] }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block (3 levels) in route!
            route_eval { block[*args] }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in route_eval
      throw :halt, yield
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block (2 levels) in route!
            route_eval { block[*args] }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in process_route
        block ? block[self, values] : yield(self, values)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in catch
      catch(:pass) do
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in process_route
      catch(:pass) do
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in route!
          returned_pass_block = process_route(pattern, keys, conditions) do |*args|
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in each
        routes.each do |pattern, keys, conditions, block|
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in route!
        routes.each do |pattern, keys, conditions, block|
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in dispatch!
        route!
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in invoke
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in catch
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in invoke
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in dispatch!
      invoke do
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in call!
      invoke { dispatch! }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in invoke
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in catch
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in invoke
      res = catch(:halt) { yield }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call!
      invoke { dispatch! }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
      dup.call!(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb in call
        status, headers, body = @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb in call
        app.call env
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb in call
        status, headers, body = app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb in call
        result or app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb in call
        result or app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb in call
        status, headers, body        = @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/logger.rb in call
      @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/commonlogger.rb in call
      status, header, body = @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
        call_without_check(env)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
      env['sinatra.commonlogger'] ? @app.call(env) : super
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/head.rb in call
    status, headers, body = @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb in call
      @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb in call
      @app.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
      result, callback = app.call(env), env['async.callback']
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
      @stack.call(env)
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in block in call
        synchronize { prototype.call(env) }
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in synchronize
          yield
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb in call
        synchronize { prototype.call(env) }
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb in service
        status, headers, body = @app.call(env)
/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb in service
      si.service(req, res)
/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb in run
          server.service(req, res)
/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/webrick/server.rb in block in start_thread
          block ? block.call(sock) : run(sock)
ArgumentError位于/
参数数目错误(1代表0)
/打开的usr/local/ceral/ruby/2.2.3/lib/ruby/2.2.0/tempfile.rb
def打开
/open中的usr/local/ceral/ruby/2.2.3/lib/ruby/2.2.0/open-uri.rb
name.open(*rest和block)
/打开的usr/local/lib/ruby/gems/2.2.0/gems/mini_-magick-4.3.6/lib/mini_-magick/image.rb
open(path_或url,“rb”)do|文件|
块中的server.rb
image=MiniMagick::image.open(参数['user\u image'][:tempfile])
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
proc{a,p|unbound_method.bind(a.call}
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb在编译中的块中!
proc{a,p|unbound_method.bind(a.call}
/[]中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
路由_eval{block[*args]}
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb块(3层)在路线中!
路由_eval{block[*args]}
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb在路线评估中
停止,屈服
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb块(2层)在路线中!
路由_eval{block[*args]}
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb位于流程中的块中
块块[self,values]:屈服(self,values)
/捕获中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
接住做某事
/进程路径中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
接住做某事
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb在路径中的块中!
返回的_pass_block=进程_路由(模式、键、条件)do |*args|
/每个文件中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
路由。每个do |模式、键、条件、块|
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb正在运行中!
路由。每个do |模式、键、条件、块|
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb在发送中的块中!
路线!
/调用中块中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/捕获中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/发送中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb!
调用do
/调用块中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb!
调用{dispatch!}
/调用中块中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/捕获中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
res=捕获(:暂停){yield}
/usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb呼叫中!
调用{dispatch!}
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
重复呼叫!(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb
状态、标题、正文=@app.call(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb
app.call env
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb
状态、标题、正文=app.call(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb
结果或应用程序调用(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb
结果或应用程序调用(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb
状态、标题、正文=@app.call(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/logger.rb
@应用程序调用(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/commonlogger.rb
状态、标题、正文=@app.call(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
在不检查的情况下调用(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
环境['sinatra.commonlogger']@应用呼叫(环境):超级
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/head.rb
状态、标题、正文=@app.call(env)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb
@应用程序调用(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb
@应用程序调用(环境)
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
结果,callback=app.call(env),env['async.callback']
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
@stack.call(env)
/调用块中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
同步{prototype.call(env)}
/同步中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
产量
/调用中的usr/local/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb
同步{prototype.call(env)}
/usr/local/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb在服务中
状态、标题、正文=@app.call(env)
/usr/local/ceral/ruby/2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb正在服务中
si.服务(需求、资源)
/usr/local/ceral/ruby/2.2.3/lib
image = MiniMagick::Image.open(File.new(params[:user_image][:tempfile]))