我正在尝试获取以base64编码格式接收的图像的内容类型和文件名。
以下是使用POST请求发送base64编码图像的代码:
require 'net/http'
require "rubygems"
require 'active_support'
url = URI.parse('http://localhost:3000/')
image = ActiveSupport::Base64.encode64(open("public/images/rails.png").to_a.join)
post_params = {'image' => image }
Net::HTTP.post_form(url, post_params)
在控制器中,我需要获取这张图片的content-type和文件名。因此,首先我需要对其进行解码。
image = ActiveSupport::Base64.decode64(params[:image])
image_data = StringIO.new(image)
然后我卡住了!
我基本上想使用Paperclip保存这张图片。需要一些严肃的帮助!
更新: 我无法为内容类型和文件名发送参数。我只是模仿客户端发送的内容(我无法控制添加额外的参数)。