GithubHelp home page GithubHelp logo

jinshen1983 / activestorage-database-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from titovdigital/activestorage-database-service

0.0 1.0 0.0 36 KB

ActiveStorage Database Service

License: MIT License

JavaScript 2.46% Ruby 79.44% CSS 2.19% HTML 15.91%

activestorage-database-service's Introduction

Rails Database File Upload with ActiveStorage

A Rails Active Storage service implementing binary file upload to database.

This gem has been created to address lack of built-in (or widely accepted in the community) support for uploading and saving binary files in ActiveRecord model.

It is designed to be used in particular use cases where there is a need to store binary files uploads in database (such as PostgreSQL) without third-party cloud storage.

Implementation is based on Ruby on Rails 5.2+ standard Active Storage API: https://guides.rubyonrails.org/active_storage_overview.html

The gem adds a migration with a new model: an extra table that stores blob contents in a binary field. The service creates and destroys records in this table as requested by Active Storage.

Therefore, this service, once installed, can be consumed via a standard Rails Active Storage API.

Please be aware of all pros and cons of using a database for storing files before using it in production. With the right database it will provide full ACID support and can wrap file storage and deletion into transactions. It is also much easier in DevOps as there is one less service to configure. Large files or large traffic are the risky cases. Either will put an unnecessary strain on the app and database servers.

This gem has been tested with PostgreSQL.

Installation

Add this line to your application's Gemfile:

gem 'activestorage-database-service', github: 'TitovDigital/activestorage-database-service'

And then execute:

$ bundle

Add following lines to the config/storage.yml:

db:
  service: Database

Enable new storage service in development.rb and production.rb environments:

config.active_storage.service = :db

Or configure for a specific model:

class User < ApplicationRecord
  has_one_attached :avatar, service: :db
end

Copy and run database migration:

$ rake activestorage_database_service_engine:install:migrations
$ rails db:migrate

License

The gem is available as open source under the terms of the MIT License.

activestorage-database-service's People

Contributors

fnordfish avatar jacshen-ebay avatar markaschneider avatar paul-at avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.