2019-09-12 15:02:45 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-23 22:33:57 +08:00
|
|
|
module ActiveStorageConcerns
|
2019-09-12 15:02:45 +08:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def convert_variant_to_base64(variant)
|
2019-09-30 16:25:11 +08:00
|
|
|
encoded_data = Base64.strict_encode64(variant.service.download(variant.processed.key))
|
2019-09-12 15:02:45 +08:00
|
|
|
"data:#{variant.image.blob.content_type};base64,#{encoded_data}"
|
2019-09-18 21:11:51 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error e.message
|
|
|
|
"data:#{variant.image.blob.content_type};base64,"
|
2019-09-12 15:02:45 +08:00
|
|
|
end
|
|
|
|
end
|