添加git上传二进制文件接口

dev_daiao
guange 5 years ago
parent c8e270d0d1
commit 365e7a372d

@ -2,6 +2,8 @@
#
# 文档在 https://www.showdoc.cc/127895880302646?page_id=1077512172693249
#
require 'faraday'
class GitService
class << self
@ -12,6 +14,14 @@ class GitService
end
end
def make_new_multipar_file(full_file_path)
Faraday::FilePart.new(full_file_path, 'application/octet-stream')
end
def update_file_binary(params)
post_form('update_file', params)
end
private
def root_url
@ -24,6 +34,19 @@ class GitService
Rails.logger
end
def post_form(action,params)
conn = Faraday.new(root_url) do |f|
f.request:multipart
f.request:url_encoded
f.adapter:net_http
end
resp = conn.post("/api/#{action}", params)
body = resp.body
parse_return(body)
end
def post(action, params)
uri = URI.parse("#{root_url}/api/#{action}")
https = Net::HTTP.new(uri.host, uri.port)
@ -32,6 +55,11 @@ class GitService
req.body = params.to_json
res = https.request(req)
body = res.body
parse_return(body)
end
def parse_return(body)
logger.info("--uri_exec: .....res is #{body}")
content = JSON.parse(body)

Loading…
Cancel
Save