This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp | |
class Application < Rails::Application | |
if Rails.env == 'test' | |
require 'diagnostic' | |
config.middleware.use(MyApp::DiagnosticMiddleware) | |
end | |
# If previous code is not working then write code this way | |
# if Rails.env == 'test' | |
# require File.expand_path('../diagnostic', __FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a file named image_upload_to_s3.rb under services folder of your ROR project: | |
image_upload_to_s3.rb file: | |
require "aws-sdk-s3" | |
class ImageUploadToS3 | |
attr_reader :object | |
def initialize(object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Base64ToImageFile | |
extend ActiveSupport::Concern | |
def convert_base64_to_image_file(base64_data, filename = 'image') | |
return base64_data unless base64_data.present? && base64_data.is_a?(String) | |
regex = /data:image\/([a-z]{3,4});base64,/ | |
type_fetch_regex = /\/(.*?);/ | |
start_text = regex.match(base64_data) | |
type = base64_data[type_fetch_regex, 1] |