Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status

Provides a simple WebDAV storage for Shrine.


Add this line to your application's Gemfile:

gem 'shrine-webdav'


Suppose you have Report model which should be able to store data in a remote WebDAV storage.

class Report < ApplicationRecord
# == Schema Information
# Table name: reports
#  id                :uuid             not null, primary key
#  name              :string           not null
#  created_at        :datetime         not null
#  updated_at        :datetime         not null

Before you start add attributes pointing to remote files to your model you should describe Uploader class:

# app/models/reports/report_uploader.rb
class ReportUploader < Shrine
  plugin :activerecord
  plugin :logging, logger: Rails.logger

  def generate_location(_io, context)
    uuid = context[:record].id

You don't have to override method generate_location, but if you didn't you would have random file names.

Now you can add the attributes:

class Report < ApplicationRecord

Note corresponding migrations:

class AddFileAttributes < ActiveRecord::Migration[5.1]
  def change
    add_column :reports, :xls_data, :text
    add_column :reports, :pdf_data, :text

Create file shrine.rb in config/initializers/ to configure WebDAV storage:

# config/initializers/shrine.rb
require 'shrine'
require "shrine/storage/webdav"

Shrine.storages = {
  cache: '', prefix: 'your_project/cache'),
  store: '', prefix: 'your_project/store')

Now you can use your virtual attributes pdf and xls like this:

report = 'Senseless report')

# here you are going to have file sample.pdf uploaded
# to "{}.pdf"
report.pdf ='sample.pdf')

# file sample.xls is being uploading
# to "{}.xls"
report.xls ='sample.xls')

# after committing in database both files sample.pdf and sample.xls have
# been uploaded to ""

Gem also supports http options timeout and basic auth Basic usage:
  host: '',
  prefix: 'your_project/store',
  http_options: {
    basic_auth: { user: 'user', pass: 'pass' },
    timeout: { connect: 5, write: 2, read: 10 }

You can also use global timeouts like this:
  host: '',
  prefix: 'your_project/store',
  http_options: {
    timeout: 3


After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.

To install this gem onto your local machine, run bundle exec rake install.

To release a new version, update the version number in shrine-webdav.gemspec, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


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

Sponsored by FunBox