Project

uploads

0.01
No commit activity in last 3 years
No release in over 3 years
Simplified uploads for rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Uploads - Easy uploads for rails.

  1. No predefined CSS and templates.
  2. Support rails CSRF TOKEN.
  3. No middleware, just your controllers.
  4. Use as much as possible jQuery buildin functions.
  5. Works Paperclip and CarrierWave
  6. Based on file-uploader

Installation

Add it to our Gemfile

gem 'uploads'

In your controller

class UserUploadsController < ApplicationController
  # includes Uploads module for #respond_to_upload method
  include Uploads

  def create
    # create you Upload model as usual
    @upload = current_user.user_uploads.new
    
    respond_to_upload(request) do |file, response|
      # grab uploaded file
      @upload.image = file
      # try to save it
      if response[:success] = @upload.save
        # send back upload id and image preview
        response[:user_upload_id] = @upload.id
        response[:user_upload_preview_url] = @upload.image.url(:avator_editor)
      else
        # report errors if any
        response[:errors] = @upload.errors
      end
    end
  end
end

In your views

  #upload-area data-button='#upload-button' \
               data-multiple='false' \
               data-dropzones='#upload-area'
    a#upload-button Choose a photo

In your js

# application.js.coffee
...
# require anjlab/uploads
  $('#upload-area').uploader
    request:
      endpoint: '/user_uploads'
    validation:
      allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
    callbacks:
      onComplete: (id, fileName, response) ->
        console.log('onComplete')
      onProgress: (id, fileName, loaded, total) ->
        console.log('onProgress')
      onUpload: (id, fileName) ->
        console.log('onUpload')
      onError: (id, fileName, message) ->
        console.log('onError')

Examples and tutorials

uploads

This project rocks and uses MIT-LICENSE.