[英]Carrierwave encode file to base64 as process
我想解決這個問題。 我想將文件編碼為base64作為其中一個過程。
到目前為止我的代碼看起來像
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
storage :file
def extension_white_list
%w(jpg jpeg png)
end
def store_dir
"/tmp/images/#{model.class.to_s.underscore}/#{model.id}"
end
process :set_content_type
process :format_to_jpg
process :strip_metadata
process :encode_base64
def format_to_jpg
manipulate! do |img|
img.format 'jpg'
img
end
end
def strip_metadata
manipulate! do |img|
img.strip
img
end
end
def encode_base64
#What should be here?
end
end
我不確定我應該在encode_base64方法中放置什么。 編碼方法是Base64.encode64()作為參數應該發送文件內容(可能是self.read)。 但我不確定如何遵循Carrierwave的最佳實踐。
發現我不需要做任何特別的事情。
def encode_base64
File.write(path,Base64.encode64(File.read(path)))
end
是魔術嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.