接收图片并存至数据库
newrequest = Request.create
newrequest.picture = params[:picture].read
newrequest.save
发送图片给其他服务器
clnt = HTTPClient.new
uri = SERVER_URI + "push_request"
@res = clnt.post(uri, {request_id: newrequest.id, picture: get_picture(newrequest.id), text: params[:text]})
def get_picture (request_id)
request = Request.find (request_id)
send_data request.picture , :type => "image/png"
end
其他服务器端接收图片
begin
File.open(picture_new_path, 'wb') do |file|
file.write picture
end
rescue
###
else
###
end
https://gist.github.com/macek/610596
http://mattberther.com/2007/10/19/uploading-files-to-a-database-using-rails
http://archive.railsforum.com/viewtopic.php?id=4642
http://apidock.com/rails/ActionController/Streaming/send_data
http://stackoverflow.com/questions/1698386/please-help-me-send-a-jpg-file-using-send-data