GithubHelp home page GithubHelp logo

isabella232 / remote_files Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zendesk/remote_files

0.0 0.0 0.0 125 KB

A library for uploading files to multiple remote storage like Amazon S3 and Rackspace CloudFiles.

License: Apache License 2.0

Ruby 100.00%

remote_files's Introduction

RemoteFiles

A library for uploading files to multiple remote storage backends like Amazon S3.

The purpose of the library is to implement a simple interface for uploading files to multiple backends and to keep the backends in sync, so that your app will keep working when one backend is down.

Installation

Add this line to your application's Gemfile:

gem 'remote_files'

And then execute:

$ bundle

Or install it yourself as:

$ gem install remote_files

Configuration

First you configure the storage backends you want:

RemoteFiles.add_store(:s3, :primary => true) do |s3|
  s3[:provider] = 'AWS'

  s3[:aws_access_key_id]     = AWS_ACCESS_KEY_ID
  s3[:aws_secret_access_key] = AWS_SECRET_ACCESS_KEY

  s3[:directory] = 'my_s3_bucket'
end

By default RemoteFiles will store your files to all stores synchronously. This is probably not what you want, so you should tell RemoteFiles how to do it asynchronously:

class RemoteFilesSyncJob
  def initialize(identifier, stored_in)
    @file = RemoteFiles::File.new(identifier, :stored_in => stored_in)
  def

  def work
    @file.synchronize!
  end
end

RemoteFiles.synchronize_stores do |file|
  MyPreferredJobQueue.enqueue(RemoteFilesSyncJob, file.identifier, file.stored_in)
end

Usage

Once everything is configured, you can store files like this:

file = RemoteFiles::File.new(unique_file_name, :content => file_content, :content_type => content_type)
file.store!

This will store the file on one of the stores and then asynchronously copy the file to the remaining stores. RemoteFiles::File#store! will raise a RemoteFiles::Error if all storage backends are down.

If you just need to store the file in a single store, the you can use RemoteFiles::File#store_once!. It will behave exactly like RemoteFiles::File#store!, but will not asynchronously copy the file to the other stores.

Copyright and license

Copyright 2013 Zendesk

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

remote_files's People

Contributors

bquorning avatar craiglittle avatar ellimist avatar grosser avatar henders avatar nick-f avatar nickfz3n avatar staugaard avatar steved 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.