Skip to content

Commit dd89831

Browse files
committed
add context to Upload model to allow sending data-context
- allows for not polluting the session object, or when the session object isn't suitable for passing additional context information
1 parent 31f627d commit dd89831

File tree

8 files changed

+17
-6
lines changed

8 files changed

+17
-6
lines changed

app/controllers/s3_multipart/uploads_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module S3Multipart
22
class UploadsController < ApplicationController
3-
3+
44
def create
55
begin
66
upload = Upload.create(params)
@@ -20,9 +20,9 @@ def update
2020
return complete_upload if params[:parts]
2121
return sign_batch if params[:content_lengths]
2222
return sign_part if params[:content_length]
23-
end
23+
end
2424

25-
private
25+
private
2626

2727
def sign_batch
2828
begin

app/models/s3_multipart/upload.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class Upload < ::ActiveRecord::Base
77

88
def self.create(params)
99
response = initiate(params)
10-
super(key: response["key"], upload_id: response["upload_id"], name: response["name"], uploader: params["uploader"], size: params["content_size"])
10+
super(key: response["key"], upload_id: response["upload_id"], name: response["name"], uploader: params["uploader"], size: params["content_size"], context: params["context"].to_s)
1111
end
1212

1313
def execute_callback(stage, session)
1414
controller = deserialize(uploader)
15-
15+
1616
case stage
1717
when :begin
1818
controller.on_begin_callback.call(self, session) if controller.on_begin_callback

javascripts/s3mp.js

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ S3MP.prototype.initiateMultipart = function(upload, cb) {
155155
body = JSON.stringify({ object_name : upload.name,
156156
content_type : upload.type,
157157
content_size : upload.size,
158+
context : $(this.fileInputElement).data("context"),
158159
uploader : $(this.fileInputElement).data("uploader")
159160
});
160161

lib/generators/s3_multipart/install_new_migrations_generator.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class InstallNewMigrationsGenerator < Rails::Generators::Base
88

99
def create_latest_migrations
1010
copy_file "add_size_column_to_s3_multipart_uploads.rb", "db/migrate/#{migration_time}_add_size_to_s3_multipart_uploads.rb"
11+
copy_file "add_context_column_to_s3_multipart_uploads.rb", "db/migrate/#{migration_time}_add_context_to_s3_multipart_uploads.rb"
1112
end
1213

1314
private
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddContextToS3MultipartUploads < ActiveRecord::Migration
2+
def change
3+
add_column :s3_multipart_uploads, :context, :text
4+
end
5+
end
6+

lib/generators/s3_multipart/templates/uploads_table_migration.rb

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def change
88
t.string :name
99
t.string :uploader
1010
t.integer :size
11+
# additional options useful for constructing associations for the uploaded model
12+
t.text :context
1113

1214
t.timestamps
1315
end

vendor/assets/javascripts/s3_multipart/lib.js

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ S3MP.prototype.initiateMultipart = function(upload, cb) {
169169
body = JSON.stringify({ object_name : upload.name,
170170
content_type : upload.type,
171171
content_size : upload.size,
172+
context : $(this.fileInputElement).data("context"),
172173
uploader : $(this.fileInputElement).data("uploader")
173174
});
174175

vendor/assets/javascripts/s3_multipart/lib.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)