ランキングに戻る

shrinerb/shrine

Rubyshrinerb.com

File Attachment toolkit for Ruby applications

file-uploadrubyrackstorageattachmentfilesystems3background-jobsdirect-uploadormmetadata
スター成長
スター
3.3k
フォーク
276
週間成長
Issue
0
1k2k3k
2015年10月2019年5月2022年12月2026年7月
成果物RubyGemsgem install shrine
README

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.

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

Setup

Run:

bundle add shrine

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, id: nil %>
  <%= 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.

関連リポジトリ
ShareX/ShareX

ShareX is a free and open-source application that enables users to capture or record any area of their screen with a single keystroke. It also supports uploading images, text, and various file types to a wide range of destinations.

C#GNU General Public License v3.0screen-capturescreen-recorder
getsharex.com
38.7k3.9k
dropzone/dropzone

Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.

JavaScriptnpmOtherdropzonejavascript
dropzone.dev/js
18.4k3.2k
pqina/filepond

🌊 A flexible and fun JavaScript file upload library

JavaScriptnpmMIT Licensefile-uploaddrag-and-drop
pqina.nl/filepond
16.4k853
react-dropzone/react-dropzone

Simple HTML5 drag-drop zone with React.js.

TypeScriptnpmMIT Licensereactdrag-and-drop
react-dropzone.js.org
11k802
FineUploader/fine-uploader

Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.

JavaScriptnpmMIT Licensefineuploaderjavascript
fineuploader.com
8.1k1.8k
timvisee/ffsend

:mailbox_with_mail: Easily and securely share files from the command line. A fully featured Firefox Send client.

Rustcrates.ioGNU General Public License v3.0firefox-sendcli
gitlab.com/timvisee/ffsend
7.4k207
node-formidable/formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.

JavaScriptnpmMIT Licenseformmultipart-formdata
7.2k688
kalcaddle/KodExplorer

A web based file manager,web IDE / browser based code editor

PHPPackagistfilemanagerfile-sharing
kodcloud.com
6.4k1.8k
prasathmani/tinyfilemanager

Single-file PHP file manager, browser and manage your files efficiently and easily with tinyfilemanager

PHPPackagistGNU General Public License v3.0phpfilemanager
tinyfilemanager.github.io
5.9k1.8k
fengyuanchen/compressorjs

JavaScript image compressor.

JavaScriptnpmMIT Licensejavascriptimage-compression
fengyuanchen.github.io/compressorjs/
5.8k452
moxiecode/plupload

Plupload is JavaScript API for building file uploaders. It supports multiple file selection, file filtering, chunked upload, client side image downsizing and when necessary can fallback to alternative runtimes, like Flash and Silverlight.

JavaScriptnpmGNU Affero General Public License v3.0pluploadfile-upload
plupload.com
5.6k1.4k
AtalayaLabs/OxiCloud

☁️ Ultra-fast, secure & lightweight self-hosted cloud storage — your files, photos, calendars & contacts, all in one place. Built in Rust.

Rustcrates.ioMIT Licensecloudcloud-storage
atalayalabs.github.io/OxiCloud/
3.4k160