require 'base64' def splitBase64(uri) if uri.match(%r{^data:(.*?);(.*?),(.*)$}) return { :type => $1, # "image/jpg" :encoder => $2, # "base64" :data => $3, # data string :extension => $1.split('/')[1] # "jpg" } end end def transf splitdata = splitBase64(data_url) data= splitdata[:data] File.open("/mifoto.jpg","wb") do |f| f.write(Base64.decode64(data)) end end
fuente
No comments:
Post a Comment