s3_relay 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -11
- data/app/assets/javascripts/s3_relay.coffee +6 -0
- data/lib/s3_relay/version.rb +1 -1
- metadata +3 -7
- data/test/dummy/log/development.log +0 -53
- data/test/dummy/log/test.log +0 -18412
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eb3749db208e34c25730efc1bac3cdaa60cbbca
|
4
|
+
data.tar.gz: 5ab8beaaa957f5abcf41f687d82e2f7c06deea37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d6166f156b612b5619c355a19b42ede0dc6572505cd301985916c809ac6822729dd30c92a58a25bb92fc14a10d3f2cc01047ad305372abc1b31e3d101a03b22
|
7
|
+
data.tar.gz: 28f2e274966d3a849afaa2ecbaaca004c28f7de45d7fd35b9c95da668c1a0a54cec1e83d6e9253f5c56217357fca44f28e82ebcf4dc575a2dcea2aeda22ba23e
|
data/README.md
CHANGED
@@ -147,7 +147,9 @@ option like so:
|
|
147
147
|
<%= s3_relay_field @artist, :mp3_uploads, multiple: true, disposition: "attachment" %>
|
148
148
|
```
|
149
149
|
|
150
|
-
###
|
150
|
+
### Importing files
|
151
|
+
|
152
|
+
#### Processing uploads asynchronously
|
151
153
|
|
152
154
|
Use your background job processor of choice to process uploads pending
|
153
155
|
ingestion (and image processing) by your app.
|
@@ -155,25 +157,52 @@ ingestion (and image processing) by your app.
|
|
155
157
|
Say you're using [Resque](https://github.com/resque/resque) and [CarrierWave](https://github.com/carrierwaveuploader/carrierwave), you could define a job class:
|
156
158
|
|
157
159
|
```ruby
|
158
|
-
class
|
160
|
+
class ProductPhoto::Import
|
159
161
|
@queue = :photo_import
|
160
162
|
|
161
|
-
def self.perform(product_id)
|
162
|
-
@product = Product.find(
|
163
|
+
def self.perform(product_id, upload_id)
|
164
|
+
@product = Product.find(product_id)
|
165
|
+
@upload = S3Relay::Upload.find(upload_id)
|
163
166
|
|
164
|
-
@product.
|
165
|
-
|
166
|
-
upload.mark_imported!
|
167
|
-
end
|
167
|
+
@product.photos.create!(remote_file_url: @upload.private_url)
|
168
|
+
@upload.mark_imported!
|
168
169
|
end
|
169
170
|
end
|
170
171
|
```
|
171
172
|
|
172
|
-
|
173
|
-
|
173
|
+
#### Triggering upload imports for existing parent objects
|
174
|
+
|
175
|
+
If you would like to immediately enqueue a job to begin importing an upload
|
176
|
+
into its final desination, simply define a method on your parent object
|
177
|
+
called `import_upload` and that method will be called after an `S3Relay::Upload`
|
178
|
+
is created.
|
179
|
+
|
180
|
+
#### Triggering upload imports for new parent objects
|
181
|
+
|
182
|
+
If you would like to immediately enqueue a job to begin importing all of the
|
183
|
+
uploads for a new parent object following its creation, you might want to setup
|
184
|
+
a callback to enqueue those imports.
|
185
|
+
|
186
|
+
#### Examples
|
174
187
|
|
175
188
|
```ruby
|
176
|
-
|
189
|
+
class Product
|
190
|
+
|
191
|
+
# Called by s3_relay when an associated S3Relay::Upload object is created
|
192
|
+
def import_upload(upload_id)
|
193
|
+
Resque.enqueue(ProductPhoto::Import, id, upload_id)
|
194
|
+
end
|
195
|
+
|
196
|
+
after_commit :import_uploads, on: :create
|
197
|
+
|
198
|
+
# Called via after_commit to enqueue imports of S3Relay::Upload objects
|
199
|
+
def import_uploads
|
200
|
+
photo_uploads.pending.each do |upload|
|
201
|
+
Resque.enqueue(ProductPhoto::Import, id, upload.id)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
177
206
|
```
|
178
207
|
|
179
208
|
### Restricting the objects uploads can be associated with
|
@@ -4,6 +4,11 @@ displayFailedUpload = (progressColumn=null) ->
|
|
4
4
|
else
|
5
5
|
alert("File could not be uploaded")
|
6
6
|
|
7
|
+
publishEvent = (name, detail) ->
|
8
|
+
ev = document.createEvent "CustomEvent"
|
9
|
+
ev.initCustomEvent name, true, false, detail
|
10
|
+
document.dispatchEvent ev
|
11
|
+
|
7
12
|
saveUrl = (container, uuid, filename, contentType, publicUrl) ->
|
8
13
|
privateUrl = null
|
9
14
|
|
@@ -21,6 +26,7 @@ saveUrl = (container, uuid, filename, contentType, publicUrl) ->
|
|
21
26
|
public_url: publicUrl
|
22
27
|
success: (data, status, xhr) ->
|
23
28
|
privateUrl = data.private_url
|
29
|
+
publishEvent "upload:success", { uuid: uuid }
|
24
30
|
error: (xhr) ->
|
25
31
|
console.log xhr.responseText
|
26
32
|
|
data/lib/s3_relay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_relay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenny Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -212,8 +212,6 @@ files:
|
|
212
212
|
- test/dummy/config/secrets.yml
|
213
213
|
- test/dummy/db/migrate/20141021002149_create_products.rb
|
214
214
|
- test/dummy/db/schema.rb
|
215
|
-
- test/dummy/log/development.log
|
216
|
-
- test/dummy/log/test.log
|
217
215
|
- test/dummy/public/404.html
|
218
216
|
- test/dummy/public/422.html
|
219
217
|
- test/dummy/public/500.html
|
@@ -247,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
245
|
version: '0'
|
248
246
|
requirements: []
|
249
247
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.4.
|
248
|
+
rubygems_version: 2.4.3
|
251
249
|
signing_key:
|
252
250
|
specification_version: 4
|
253
251
|
summary: Direct uploads to S3 and ingestion by your Rails app.
|
@@ -283,8 +281,6 @@ test_files:
|
|
283
281
|
- test/dummy/config.ru
|
284
282
|
- test/dummy/db/migrate/20141021002149_create_products.rb
|
285
283
|
- test/dummy/db/schema.rb
|
286
|
-
- test/dummy/log/development.log
|
287
|
-
- test/dummy/log/test.log
|
288
284
|
- test/dummy/public/404.html
|
289
285
|
- test/dummy/public/422.html
|
290
286
|
- test/dummy/public/500.html
|
@@ -1,53 +0,0 @@
|
|
1
|
-
[1m[36m (6.8ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) [0m
|
2
|
-
[1m[35m (3.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
3
|
-
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
4
|
-
Migrating to CreateS3RelayUploads (20141009000804)
|
5
|
-
[1m[35m (0.1ms)[0m BEGIN
|
6
|
-
[1m[36m (5.3ms)[0m [1mCREATE TABLE "s3_relay_uploads" ("id" serial primary key, "parent_type" character varying(255), "parent_id" integer, "uuid" bytea, "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "uploaded_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) [0m
|
7
|
-
[1m[35mSQL (0.6ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
|
8
|
-
[1m[36m (0.5ms)[0m [1mCOMMIT[0m
|
9
|
-
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
10
|
-
[1m[36m (5.7ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) [0m
|
11
|
-
[1m[35m (1.6ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
12
|
-
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
13
|
-
Migrating to CreateS3RelayUploads (20141009000804)
|
14
|
-
[1m[35m (0.1ms)[0m BEGIN
|
15
|
-
[1m[36m (3.8ms)[0m [1mCREATE TABLE "s3_relay_uploads" ("id" serial primary key, "parent_type" character varying(255), "parent_id" integer, "uuid" bytea, "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) [0m
|
16
|
-
[1m[35mSQL (0.5ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
|
17
|
-
[1m[36m (0.6ms)[0m [1mCOMMIT[0m
|
18
|
-
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
19
|
-
[1m[36mActiveRecord::SchemaMigration Load (25.7ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
20
|
-
Migrating to CreateProducts (20141021002149)
|
21
|
-
[1m[35m (0.2ms)[0m BEGIN
|
22
|
-
[1m[36m (69.1ms)[0m [1mCREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) [0m
|
23
|
-
[1m[35mSQL (4.9ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
|
24
|
-
[1m[36m (5.7ms)[0m [1mCOMMIT[0m
|
25
|
-
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
26
|
-
[1m[36m (6.1ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) [0m
|
27
|
-
[1m[35m (1.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
28
|
-
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
29
|
-
Migrating to CreateS3RelayUploads (20141009000804)
|
30
|
-
[1m[35m (0.1ms)[0m BEGIN
|
31
|
-
[1m[36m (4.7ms)[0m [1mCREATE TABLE "s3_relay_uploads" ("id" serial primary key, "uuid" bytea, "parent_type" character varying(255), "parent_id" integer, "upload_type" character varying(255), "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) [0m
|
32
|
-
[1m[35mSQL (0.8ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
|
33
|
-
[1m[36m (0.8ms)[0m [1mCOMMIT[0m
|
34
|
-
Migrating to CreateProducts (20141021002149)
|
35
|
-
[1m[35m (0.3ms)[0m BEGIN
|
36
|
-
[1m[36m (5.1ms)[0m [1mCREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) [0m
|
37
|
-
[1m[35mSQL (0.2ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
|
38
|
-
[1m[36m (0.6ms)[0m [1mCOMMIT[0m
|
39
|
-
[1m[35mActiveRecord::SchemaMigration Load (0.4ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
40
|
-
[1m[36m (20.7ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL) [0m
|
41
|
-
[1m[35m (9.3ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
42
|
-
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
43
|
-
Migrating to CreateS3RelayUploads (20141009000804)
|
44
|
-
[1m[35m (0.1ms)[0m BEGIN
|
45
|
-
[1m[36m (24.8ms)[0m [1mCREATE TABLE "s3_relay_uploads" ("id" serial primary key, "uuid" bytea, "user_id" integer, "parent_type" character varying(255), "parent_id" integer, "upload_type" character varying(255), "filename" text, "content_type" character varying(255), "state" character varying(255), "data" json DEFAULT '{}', "pending_at" timestamp, "imported_at" timestamp, "created_at" timestamp, "updated_at" timestamp) [0m
|
46
|
-
[1m[35mSQL (6.2ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141009000804"]]
|
47
|
-
[1m[36m (6.0ms)[0m [1mCOMMIT[0m
|
48
|
-
Migrating to CreateProducts (20141021002149)
|
49
|
-
[1m[35m (11.0ms)[0m BEGIN
|
50
|
-
[1m[36m (9.0ms)[0m [1mCREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "created_at" timestamp, "updated_at" timestamp) [0m
|
51
|
-
[1m[35mSQL (1.3ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20141021002149"]]
|
52
|
-
[1m[36m (0.9ms)[0m [1mCOMMIT[0m
|
53
|
-
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|