从Ruby on Rails应用程序向节点服务器发送数据

时间:2018-06-19 01:33:45

标签: ruby-on-rails node.js

我有一个sipmle Ruby on Rails应用程序。

kpi.jtl, detail.jtl and error.jtl

index.html.erb

<h3>Import</h3> <%= form_tag import_zip_code_data_path, multipart: true do %> <%= file_field_tag :file %> <%= submit_tag "Upload" %> <% end %>

zip_code_data_controller.rb

服务器端,我正在使用节点构建API:

def import
    uploaded_io = params[:file]
    begin
      uri = URI('http://localhost:4001/zip')
      http = Net::HTTP.new(uri.host, uri.port)
      req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
      req.body = { "uploaded_io" => uploaded_io}.to_json
      res = http.request(req)
      puts "response #{res.body}" // response Hey, it works!
      puts JSON.parse(res.body)
    rescue => e
      puts "failed #{e}" // failed 743: unexpected token at 'Hey, it works!'
    end
  end
end

我无法查看我使用发布请求发送的有效负载。我只能查看标题(app.post('/zip', (req, res) => { console.log('req.headers\n', req.headers) // I can see the headers I'm sending from the rails client console.log('req.body\n', req.body) // Undefined res.send("Hey, it works!") }) )。

是否可以查看从我的节点服务器中的Rails应用程序上传的文件?

0 个答案:

没有答案