我使用Carrierwave添加了使用base64映像的解决方案,以便从java类上传图像.这就是我的FileUploader类的样子 - 我相信问题出在哪里:
# encoding: utf-8
class FileUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
#START FROM BASE64 POST LINKED ABOVE
class FilelessIO < StringIO
attr_accessor :original_filename
attr_accessor :content_type
end
before :cache, :convert_base64
def convert_base64(file)
if file.respond_to?(:original_filename) &&
file.original_filename.match(/^base64:/)
fname = file.original_filename.gsub(/^base64:/, '')
ctype = file.content_type
decoded = Base64.decode64(file.read)
file.file.tempfile.close!
decoded = FilelessIO.new(decoded)
decoded.original_filename …Run Code Online (Sandbox Code Playgroud) 有没有办法将字符串转换为ActionDispatch::Http::UploadedFile
我需要它能够在 API 请求中传递文件路径来处理将 Excel 插入数据库的操作,因为我想使用 REST API 而不是浏览器来上传文件。
谢谢