Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use WebDav to store uploads

  • Loading branch information...
commit 132a45fc4a018d67b483a1d053de530f12e28077 1 parent 2a512bb
@mutle authored
View
1  Gemfile
@@ -15,6 +15,7 @@ gem "tire"
gem 'newrelic_rpm'
gem 'statsd-ruby', :require => "statsd"
gem 'carrierwave'
+gem 'net_dav'
# Gems used only for assets and not required
# in production environments by default.
View
3  Gemfile.lock
@@ -79,6 +79,8 @@ GEM
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.5.0)
+ net_dav (0.5.0)
+ nokogiri (>= 1.3.0)
newrelic_rpm (3.5.4.33)
nokogiri (1.5.5)
pg (0.14.1)
@@ -174,6 +176,7 @@ DEPENDENCIES
html-pipeline
jquery-rails
json
+ net_dav
newrelic_rpm
pg (~> 0.14.1)
rails (= 3.2.9)
View
3  config/initializers/carrierwave.rb
@@ -1,3 +1,4 @@
+require 'carrierwave/storage/webdav'
CarrierWave.configure do |config|
- config.storage = Rails.env.production? ? :webdav : :file
+ config.storage = Rails.env.production? ? CarrierWave::Storage::Webdav : :file
end
View
49 lib/carrierwave/storage/webdav.rb
@@ -0,0 +1,49 @@
+require 'net/dav'
+
+module CarrierWave
+ module Storage
+ class Webdav < Abstract
+
+ class File
+ attr_reader :path
+ def server_name
+ ENV['WEBDAV_SERVER']
+ end
+ def server_url
+ "http://#{server_name}/"
+ end
+ def connection
+ @connection ||= Net::DAV.new(server_url)
+ end
+ def attributes
+ file.attributes
+ end
+ def extension
+ path.split('.').last
+ end
+ def initialize(uploader, base, path)
+ @uploader, @base, @path = uploader, base, path
+ end
+ def store(new_file)
+ connection.put(@uploader.store_path, new_file.to_file, new_file.size)
+ true
+ end
+ def url(options = {})
+ "#{server_url}/#{path}"
+ end
+ end
+
+
+ def store!(file)
+ f = CarrierWave::Storage::Webdav::File.new uploader, self, uploader.store_path
+ f.store(file)
+ f
+ end
+
+ def retrieve!(identifier)
+ CarrierWave::Storage::Fog::File.new(uploader, self, uploader.store_path(identifier))
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.