From 7797523346986fc7c9ddec75da72e109a534cf7b Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 6 Oct 2012 14:10:37 +0300 Subject: [PATCH] set files content type --- .gitignore | 1 + app/assets/javascripts/s3_direct_upload.js.coffee | 14 +++++++++++++- lib/s3_direct_upload/form_helper.rb | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ec89a4..8a0f970 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ spec/gallery-jquery-fileupload .bundle .config .yardoc +.idea Gemfile.lock InstalledFiles _yardoc diff --git a/app/assets/javascripts/s3_direct_upload.js.coffee b/app/assets/javascripts/s3_direct_upload.js.coffee index 2510a16..42e604a 100644 --- a/app/assets/javascripts/s3_direct_upload.js.coffee +++ b/app/assets/javascripts/s3_direct_upload.js.coffee @@ -27,4 +27,16 @@ jQuery -> fail: (e, data) -> alert("#{data.files[0].name} failed to upload.") console.log("Upload failed:") - console.log(data) \ No newline at end of file + console.log(data) + + formData: (form) -> + data = form.serializeArray() + fileType = "" + if "type" of @files[0] + fileType = @files[0].type + data.push + name: "Content-Type" + value: fileType + + data + diff --git a/lib/s3_direct_upload/form_helper.rb b/lib/s3_direct_upload/form_helper.rb index 31c140d..4164480 100644 --- a/lib/s3_direct_upload/form_helper.rb +++ b/lib/s3_direct_upload/form_helper.rb @@ -65,6 +65,7 @@ def policy_data ["starts-with", "$utf8", ""], ["starts-with", "$key", ""], ["content-length-range", 0, @options[:max_file_size]], + ["starts-with","$Content-Type",""], {bucket: @options[:bucket]}, {acl: @options[:acl]} ]