npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnix/activestorage-resumable

v1.0.0

Published

Resumable support for ActiveStorage

Downloads

2

Readme

Active Storage Resumable

Active Storage Resumable allow you to continue an upload even after a browser restart. Currently it only supports Google Cloud Storage.

This library augments Active Storage direct uploads to support resumable uploads with almost identical semantics. If you already uses direct upload, turn it resumable is straightforward.

Installation

First setup Active Storage to use GCS.

Add this line to your application's Gemfile:

gem 'activestorage-resumable'

And then execute:

$ bundle
$ rails active_storage_resumable:install:migrations
$ rails db:migrate

Resumable uploads

Active Storage Resumable, also includes a JavaScript library, that uploads file in chunks, saving the progress in localStorage, allowing to resume an upload even after a browser restart.

Resumable upload installation

  1. Include activestorage-resumable.js in your application's JavaScript bundle.

    Using the asset pipeline:

    //= require activestorage-resumable

    Using the npm package:

    require("@fnix/activestorage-resumable").start()
  2. Annotate file inputs with the resumable upload URL.

    <%= form.file_field :attachments, multiple: true, resumable_upload: true %>
  3. That's it! Uploads begin upon form submission.

Resumable upload JavaScript events

| Event name | Event target | Event data (event.detail) | Description | | --- | --- | --- | --- | | resumable-uploads:start | <form> | None | A form containing files for resumable upload fields was submitted. | | resumable-upload:initialize | <input> | {id, file} | Dispatched for every file after form submission. | | resumable-upload:start | <input> | {id, file} | A resumable upload is starting. | | resumable-upload:before-blob-request | <input> | {id, file, xhr} | Before making a request to your application for resumable upload metadata. | | resumable-upload:before-storage-request | <input> | {id, file, gcsBrowserUpload} | Before making a request to store a file. | | resumable-upload:progress | <input> | {id, file, progress} | As requests to store files progress. | | resumable-upload:error | <input> | {id, file, error} | An error occurred. An alert will display unless this event is canceled. | | resumable-upload:end | <input> | {id, file} | A resumable upload has ended. | | resumable-uploads:end | <form> | None | All resumable uploads have ended. |

The events are almost identical to Active Storage direct upload. The bigger difference is in before-storage-request, instead of a XHR, it uses an Upload object from @fnix/gcs-browser-upload. Resumable uploads are transfered in chunks, so it's not very useful to return the XHR of the first chunk. Another small change is in the progress event data, it's not a real ProgressEvent, it's only a faker with the same ProgressEvent properties.

Active Storage extensions

We added three scopes for ActiveStorage::Blob:

  • ActiveStorage::Blob.resumable: Returns all resumable blobs not attached to any model;
  • ActiveStorage::Blob.active_resumable: Returns all unfinished resumable blobs created in the last week (the duration of a resumable session URI). You can use this to show for your users the uploads that can be resumed;
  • ActiveStorage::Blob.expired_resumable: This is most for internal use, we use it to cleanup unfinished resumable blobs.

We also added the instance method uploaded_bytes to ActiveStorage::Blob so you can show to your users the progress of unfinished resumable blobs.

License

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