activestorage-resumable 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/activestorage/resumable/version.rb +1 -1
- data/lib/activestorage_extensions/blob.rb +8 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb92b9f960cefc981ffb50b6bfce65e16cab57098074720359925dd270d18a18
|
4
|
+
data.tar.gz: 7612369a85184fae18a5ebc1ebc75723952d93efd76ee6f1a8d80b4d26029322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2888771c2c559d58de0b983673a8c24c8962aca70871725fe39296cc50478e452a23a476abb8824a170f11243efa797ef59836beda743dda700083f11aa0a32e
|
7
|
+
data.tar.gz: 686b52a7baf55727554f0edb96e836cae17e6c2017e2f15f0c17684e17a04798fcec7ab52fc69610e7c7c99ee884b75c7b107875a44293722b8470fe3f5af257
|
data/README.md
CHANGED
@@ -27,7 +27,15 @@ Active Storage Resumable, also includes a JavaScript library, that uploads file
|
|
27
27
|
localStorage, allowing to resume an upload even after a browser restart.
|
28
28
|
|
29
29
|
### Resumable upload installation
|
30
|
-
1.
|
30
|
+
1. Export an environment variable called UPLOAD_ORIGIN_URL with the upload origin URL, for example
|
31
|
+
'http://localhost:3000'. You can also create a `config/initializers/activestorage_resumable.rb` with the following:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
ActiveStorage::Resumable.configure do |config|
|
35
|
+
config.upload_origin_url = 'https://mydomain.test:3000'
|
36
|
+
end
|
37
|
+
```
|
38
|
+
2. Include `activestorage-resumable.js` in your application's JavaScript bundle.
|
31
39
|
|
32
40
|
Using the asset pipeline:
|
33
41
|
```js
|
@@ -37,12 +45,12 @@ localStorage, allowing to resume an upload even after a browser restart.
|
|
37
45
|
```js
|
38
46
|
require("@fnix/activestorage-resumable").start()
|
39
47
|
```
|
40
|
-
|
48
|
+
3. Annotate file inputs with the resumable upload URL.
|
41
49
|
|
42
50
|
```ruby
|
43
51
|
<%= form.file_field :attachments, multiple: true, resumable_upload: true %>
|
44
52
|
```
|
45
|
-
|
53
|
+
4. That's it! Uploads begin upon form submission.
|
46
54
|
|
47
55
|
### Resumable upload JavaScript events
|
48
56
|
|
@@ -2,18 +2,17 @@
|
|
2
2
|
|
3
3
|
ActiveSupport.on_load(:active_storage_blob) do
|
4
4
|
class ActiveStorage::Blob
|
5
|
-
before_create do
|
6
|
-
self.resumable_url = service.url_for_resumable_upload(key, content_type)
|
7
|
-
end
|
8
|
-
|
9
5
|
scope :resumable, -> { unattached.where.not(resumable_url: nil) }
|
10
6
|
scope :active_resumable, -> { resumable.where('active_storage_blobs.created_at >= ?', 7.days.ago) }
|
11
7
|
scope :expired_resumable, -> { resumable.where('active_storage_blobs.created_at < ?', 7.days.ago) }
|
12
8
|
|
13
9
|
def self.find_or_create_before_resumable_upload!(filename:, byte_size:, checksum:, content_type: nil, metadata: nil)
|
14
|
-
|
15
|
-
find_or_create_by!
|
16
|
-
|
10
|
+
expired_resumable.destroy_all
|
11
|
+
active_resumable.find_or_create_by!(
|
12
|
+
filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type, metadata: metadata
|
13
|
+
) do |blob|
|
14
|
+
blob.resumable_url = blob.service_url_for_resumable_upload
|
15
|
+
end
|
17
16
|
end
|
18
17
|
|
19
18
|
def uploaded_bytes
|
@@ -29,9 +28,8 @@ ActiveSupport.on_load(:active_storage_blob) do
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
def service_url_for_resumable_upload
|
33
|
-
service.url_for_resumable_upload key,
|
34
|
-
content_length: byte_size, checksum: checksum
|
31
|
+
def service_url_for_resumable_upload
|
32
|
+
service.url_for_resumable_upload key, content_type: content_type
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-resumable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kadu Diógenes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|