Module: ActiveStorageSupport::Base64Attach
- Defined in:
- lib/active_storage_support/base64_attach.rb
Class Method Summary collapse
- .attachment_from_data(attachment) ⇒ Object
-
.content_type(headers) ⇒ Object
rubocop:enable Metrics/AbcSize.
-
.fill_attachment_data(attachment, base64_data) ⇒ Object
rubocop:disable Metrics/AbcSize.
Class Method Details
.attachment_from_data(attachment) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/active_storage_support/base64_attach.rb', line 6 def () = .to_h if .is_a?(ActionController::Parameters) if .is_a?(Hash) = .symbolize_keys (, .delete(:data)) end end |
.content_type(headers) ⇒ Object
rubocop:enable Metrics/AbcSize
30 31 32 33 |
# File 'lib/active_storage_support/base64_attach.rb', line 30 def content_type(headers) headers =~ /^data:(.*?)$/ Regexp.last_match(1).split(';base64').first end |
.fill_attachment_data(attachment, base64_data) ⇒ Object
rubocop:disable Metrics/AbcSize
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_storage_support/base64_attach.rb', line 18 def (, base64_data) return unless base64_data.try(:is_a?, String) && base64_data.strip.start_with?('data') headers, data = base64_data.split(',') decoded_data = Base64.decode64(data) [:io] = StringIO.new(decoded_data) [:content_type] ||= content_type(headers) [:filename] ||= Time.current.to_i.to_s end |