All Projects → shrinerb → Shrine

shrinerb / Shrine

Licence: mit
File Attachment toolkit for Ruby applications

Programming Languages

ruby
36898 projects - #4 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Shrine

Flydrive
☁️ Flexible and Fluent framework-agnostic driver based system to manage storage in Node.js
Stars: ✭ 275 (-90.53%)
Mutual labels:  s3, storage, filesystem
Diskover
File system crawler, disk space usage, file search engine and file system analytics powered by Elasticsearch
Stars: ✭ 977 (-66.35%)
Mutual labels:  metadata, storage, filesystem
Diskover Web
Web file manager, disk space usage, storage search engine and file system analytics for diskover
Stars: ✭ 121 (-95.83%)
Mutual labels:  metadata, storage, filesystem
Juicefs
JuiceFS is a distributed POSIX file system built on top of Redis and S3.
Stars: ✭ 4,262 (+46.81%)
Mutual labels:  s3, storage, filesystem
Infinit
The Infinit policy-based software-defined storage platform.
Stars: ✭ 363 (-87.5%)
Mutual labels:  s3, storage, filesystem
Mc
MinIO Client is a replacement for ls, cp, mkdir, diff and rsync commands for filesystems and object storage.
Stars: ✭ 1,962 (-32.41%)
Mutual labels:  s3, storage, filesystem
S5cmd
Parallel S3 and local filesystem execution tool.
Stars: ✭ 565 (-80.54%)
Mutual labels:  s3, storage, filesystem
Tus Ruby Server
Ruby server for tus resumable upload protocol
Stars: ✭ 172 (-94.08%)
Mutual labels:  s3, storage, filesystem
vzvol
vzvol is a general use ZFS zvol management tool, that handles creation, destruction, listing, and formatting with various FSes, in an easy to use single program
Stars: ✭ 27 (-99.07%)
Mutual labels:  storage, filesystem
minio-rclone-webdav-server
A @rclone served WebDAV server with @minio as the s3 storage backend docker example
Stars: ✭ 17 (-99.41%)
Mutual labels:  storage, s3
S4
S4 is 100% S3 compatible storage, accessed through Tor and distributed using IPFS.
Stars: ✭ 67 (-97.69%)
Mutual labels:  storage, s3
chicon-rs
A file abstraction system for Rust
Stars: ✭ 55 (-98.11%)
Mutual labels:  filesystem, s3
go-fsimpl
Go io/fs.FS filesystem implementations for various URL schemes
Stars: ✭ 225 (-92.25%)
Mutual labels:  filesystem, s3
storage
Go library providing common interface for working across multiple cloud storage backends
Stars: ✭ 154 (-94.7%)
Mutual labels:  storage, s3
gcsfs
Google Cloud Storage filesystem for PyFilesystem2
Stars: ✭ 36 (-98.76%)
Mutual labels:  storage, filesystem
gasper
Gasper is a CLI for safe, privacy-aware file storage based on Shamir's Secret Sharing
Stars: ✭ 37 (-98.73%)
Mutual labels:  storage, file-upload
Less3
Less3 is an S3-compatible object storage server that runs on your laptop, servers, just about anywhere!
Stars: ✭ 16 (-99.45%)
Mutual labels:  storage, s3
MeowDB.js
Database in JSON (Node.JS Library)
Stars: ✭ 12 (-99.59%)
Mutual labels:  storage, filesystem
acid-store
A library for secure, deduplicated, transactional, and verifiable data storage
Stars: ✭ 48 (-98.35%)
Mutual labels:  filesystem, s3
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-98.73%)
Mutual labels:  storage, filesystem

Shrine

Shrine logo: a red paperclip

Shrine is a toolkit for handling file attachments in Ruby applications. Some highlights:

If you're curious how it compares to other file attachment libraries, see the Advantages of Shrine. Otherwise, follow along with the Getting Started guide.

Links

Resource URL
Website & Documentation shrinerb.com
Demo code Roda / Rails
Wiki github.com/shrinerb/shrine/wiki
Help & Discussion discourse.shrinerb.com

Setup

Add the gem to your Gemfile:

# Gemfile
gem "shrine", "~> 3.0"

Then add config/initializers/shrine.rb which sets up the storage and loads ORM integration:

require "shrine"
require "shrine/storage/file_system"

Shrine.storages = {
  cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
  store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"),       # permanent
}

Shrine.plugin :activerecord           # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data    # extracts metadata for assigned cached files

Next, add the <name>_data column to the table you want to attach files to. For an "image" attachment on a photos table this would be an image_data column:

$ rails generate migration add_image_data_to_photos image_data:text # or :jsonb

If using jsonb consider adding a gin index for fast key-value pair searchability within image_data.

Now create an uploader class (which you can put in app/uploaders) and register the attachment on your model:

class ImageUploader < Shrine
  # plugins and uploading logic
end
class Photo < ActiveRecord::Base
  include ImageUploader::Attachment(:image) # adds an `image` virtual attribute
end

In our views let's now add form fields for our attachment attribute that will allow users to upload files:

<%= form_for @photo do |f| %>
  <%= f.hidden_field :image, value: @photo.cached_image_data %>
  <%= f.file_field :image %>
  <%= f.submit %>
<% end %>

When the form is submitted, in your controller you can assign the file from request params to the attachment attribute on the model:

class PhotosController < ApplicationController
  def create
    Photo.create(photo_params) # attaches the uploaded file
    # ...
  end

  private

  def photo_params
    params.require(:photo).permit(:image)
  end
end

Once a file is uploaded and attached to the record, you can retrieve the file URL and display it on the page:

<%= image_tag @photo.image_url %>

See the Getting Started guide for further documentation.

Inspiration

Shrine was heavily inspired by Refile and Roda. From Refile it borrows the idea of "backends" (here named "storages"), attachment interface, and direct uploads. From Roda it borrows the implementation of an extensible plugin system.

Similar libraries

  • Paperclip
  • CarrierWave
  • Dragonfly
  • Refile
  • Active Storage

Contributing

Please refer to the contributing page.

Code of Conduct

Everyone interacting in the Shrine project’s codebases, issue trackers, and mailing lists is expected to follow the Shrine code of conduct.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].