Class: DecodeXlog::Decode

Inherits:
Object
  • Object
show all
Defined in:
lib/decode_xlog.rb

Class Method Summary collapse

Class Method Details

.decode(file_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/decode_xlog.rb', line 10

def self.decode(file_path)

  url = URI("http://192.168.11.61:8080/decode")
  # 这边修改了端口号  nginx 进行了端口转发
  # url = URI("http://192.168.11.61:8080/decode/")

  http = Net::HTTP.new(url.host, url.port);
  request = Net::HTTP::Post.new(url)
  form_data = [['file', File.open(file_path)]]
  request.set_form form_data, 'multipart/form-data'
  response = http.request(request)
  data = response.read_body

  to_file_path = file_path + '.log'
  file = File.new to_file_path, 'w+'
  file.binmode
  file << data
  file.flush
  file.close

  puts file.path

end