Skip to content

Instantly share code, notes, and snippets.

View salahuddin-rakib's full-sized avatar

Gazi Salahuddin salahuddin-rakib

  • Dhaka, Bangladesh
View GitHub Profile
@salahuddin-rakib
salahuddin-rakib / application.rb
Created August 16, 2023 09:34
Observing errors from middleware
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__)
# 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)
@salahuddin-rakib
salahuddin-rakib / base64_to_image_file.rb
Last active August 13, 2022 09:21
It shows how we can convert base64 text to an image file.
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]