Home

Awesome

Resumable (chunked) uploads in Rails 4.2 using Paperclip and jQuery File Upload

Description

This is an example implementation of jQuery File Upload in Rails 4.2 using Paperclip. The app uses the gem jquery-fileupload-rails to integrate the relevant libraries into the Rails Asset Pipeline.

Installation

bundle install
rake db:create && rake db:migrate

Features

The app has one model Course, which has_attached_file :upload. Once a Course has been created, the user is redirected to the upload action of CoursesController. The user can choose a local file to upload.

When the user initiates the upload, jQuery File Upload does an AJAX request to the resume_upload action in order to establish whether there is an unfinished/interrupted upload. A JSON contianing information about the already uploaded bytes is returned. jQuery File Upload will then continue the upload from the last uploaded chunk (or from the beginning).

The PATCH request containing the first or following chunk of the uploaded file is processed by the do_upload action. This action checks again whether the file exists in the system.

Once the file upload has been completed, the callback of jQuery File Upload triggers an AJAX request to the update_status action, which make sure that Course.status is set from 'uploading' to 'uploaded'.

Some remarks