Sha256: 192c6cb70066f3f7e2911e5beb532e41ce8190761d2d0cf4a883942543270436
Contents?: true
Size: 662 Bytes
Versions: 1
Compression:
Stored size: 662 Bytes
Contents
# Helper method to decode a base64 file and create a StringIO file module ActiveStorageSupport module Base64Attach module_function def attachment_from_data(attachment) if attachment.is_a?(Hash) base64_data = attachment.delete(:data) if base64_data.try(:is_a?, String) && base64_data =~ /^data:(.*?);(.*?),(.*)$/ attachment[:io] = StringIO.new(Base64.decode64(Regexp.last_match(3))) attachment[:content_type] = Regexp.last_match(1) unless attachment[:content_type] attachment[:filename] = Time.current.to_i.to_s unless attachment[:filename] end end attachment end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_storage_base64-0.1.1 | lib/active_storage_support/base64_attach.rb |