diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index f6fce8d87..0cae132a5 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -97,21 +97,8 @@ module ReportsHelper end # "Hack" to omit file preview URL because of WKHTML issues - def report_image_asset_url(asset, type = :asset, klass = nil) - prefix = '' - if ENV['PAPERCLIP_STORAGE'].present? && - ENV['MAIL_SERVER_URL'].present? && - ENV['PAPERCLIP_STORAGE'] == 'filesystem' - prefix = ENV['MAIL_SERVER_URL'] - end - if !prefix.empty? && - !prefix.include?('http://') && - !prefix.include?('https://') - prefix = "http://#{prefix}" - end - size = type == :tiny_mce_asset ? :large : :medium - url = prefix + asset.url(size, timeout: Constants::URL_LONG_EXPIRE_TIME) - image_tag(url, class: klass) + def report_image_asset_url(asset, _type = :asset, klass = nil) + image_tag(asset.generate_base64(:medium), class: klass) end # "Hack" to load Glyphicons css directly from the CDN diff --git a/app/models/asset.rb b/app/models/asset.rb index 6d7b332e6..a03a27882 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -493,6 +493,16 @@ class Asset < ApplicationRecord !locked? && %r{^image/#{Regexp.union(Constants::WHITELISTED_IMAGE_TYPES_EDITABLE)}} =~ file.content_type end + def generate_base64(style) + image = if file.options[:storage].to_sym == :s3 + URI.parse(url(style)).open.to_a.join + else + File.open(file.path(style)).to_a.join + end + encoded_data = Base64.strict_encode64(image) + "data:#{file_content_type};base64,#{encoded_data}" + end + protected # Checks if attachments is an image (in post processing imagemagick will diff --git a/db/schema.rb b/db/schema.rb index 42cf7ba6d..ba5dc8029 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "updated_at", null: false t.string "file_file_name" t.string "file_content_type" - t.integer "file_file_size" + t.bigint "file_file_size" t.datetime "file_updated_at" t.bigint "created_by_id" t.bigint "last_modified_by_id" @@ -169,7 +169,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "updated_at", null: false t.string "workflowimg_file_name" t.string "workflowimg_content_type" - t.integer "workflowimg_file_size" + t.bigint "workflowimg_file_size" t.datetime "workflowimg_updated_at" t.uuid "uuid" t.index ["archived_by_id"], name: "index_experiments_on_archived_by_id" @@ -737,14 +737,14 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "updated_at", null: false t.string "file_file_name" t.string "file_content_type" - t.integer "file_file_size" + t.bigint "file_file_size" t.datetime "file_updated_at" end create_table "tiny_mce_assets", force: :cascade do |t| t.string "image_file_name" t.string "image_content_type" - t.integer "image_file_size" + t.bigint "image_file_size" t.datetime "image_updated_at" t.integer "estimated_size", default: 0, null: false t.integer "step_id" @@ -857,7 +857,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "updated_at", null: false t.string "avatar_file_name" t.string "avatar_content_type" - t.integer "avatar_file_size" + t.bigint "avatar_file_size" t.datetime "avatar_updated_at" t.string "confirmation_token" t.datetime "confirmed_at" @@ -924,7 +924,7 @@ ActiveRecord::Schema.define(version: 20190520135317) do t.datetime "updated_at", null: false t.string "zip_file_file_name" t.string "zip_file_content_type" - t.integer "zip_file_file_size" + t.bigint "zip_file_file_size" t.datetime "zip_file_updated_at" t.string "type" t.index ["user_id"], name: "index_zip_exports_on_user_id"