s3_direct_upload 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1ed6e265b4f74392b3fc0ab3c58b22a19041e61
4
- data.tar.gz: 60545e543bac0c5feadf0abd5e5ce268b276e214
3
+ metadata.gz: c8498cbc874d173965eda14055195f6e79899cad
4
+ data.tar.gz: 99c83432f1258e3c801001df3ecae08811277d7c
5
5
  SHA512:
6
- metadata.gz: 4550009b9508b104ec290b3c70a7a6f1263b183c262e1e2e519beb7c8d4ee1b69c747c67c51e0d3e8e6e0619e8de98b3daf666ebe1a536b824934800a41a6c59
7
- data.tar.gz: 60c03de6349abdcceadc9e7a03212d26fad2a5c31b50e8d79d78800522e628607a6d3ef343e7801b0739f1ce46eafd9503479e4a14aba6e503a37f967d6da01a
6
+ metadata.gz: 7e2d46240bd66f0363f1595ff793ca6a49f34f7e1dc5eb8be2bf134d1a652cb7eb1372cb7ea27087305af6b4c89f03263fb4c6aae876b7fbab57d4aadd5e0bda
7
+ data.tar.gz: e7cce42b04cdb3468f9500cf68103b3f8b82a3a795de65a251d7722d63f2a8f34cc3087a991e1cac1643c825efece57c589a356e30250f13d1a8515d2196c031
data/README.md CHANGED
@@ -19,6 +19,7 @@ S3DirectUpload.config do |c|
19
19
  c.secret_access_key = "" # your secret access key
20
20
  c.bucket = "" # your bucket name
21
21
  c.region = "" # region prefix of your bucket url (optional), eg. "s3-eu-west-1"
22
+ c.url = "" # S3 API endpoint (optional), eg. "https://#{c.bucket}.s3.amazonaws.com/"
22
23
  end
23
24
  ```
24
25
 
@@ -57,6 +58,8 @@ Create a new view that uses the form helper `s3_uploader_form`:
57
58
  <% end %>
58
59
  ```
59
60
 
61
+ Note: Its required that the file_field_tag is named 'file'.
62
+
60
63
  Then in your application.js.coffee, call the S3Uploader jQuery plugin on the element you created above:
61
64
  ```coffeescript
62
65
  jQuery ->
@@ -225,7 +228,7 @@ end
225
228
  ```
226
229
 
227
230
  Alternately, if you'd prefer for S3 to delete your old uploads automatically, you can do
228
- so by setting your bucket's
231
+ so by setting your bucket's
229
232
  [Lifecycle Configuration](http://docs.aws.amazon.com/AmazonS3/latest/UG/LifecycleConfiguration.html).
230
233
 
231
234
  ## Contributing / TODO
@@ -59,21 +59,19 @@ $.fn.S3Uploader = (options) ->
59
59
  done: (e, data) ->
60
60
  content = build_content_object $uploadForm, data.files[0], data.result
61
61
 
62
- to = $uploadForm.data('callback-url')
63
- if to
62
+ callback_url = $uploadForm.data('callback-url')
63
+ if callback_url
64
64
  content[$uploadForm.data('callback-param')] = content.url
65
65
 
66
66
  $.ajax
67
67
  type: $uploadForm.data('callback-method')
68
- url: to
68
+ url: callback_url
69
69
  data: content
70
70
  beforeSend: ( xhr, settings ) -> $uploadForm.trigger( 'ajax:beforeSend', [xhr, settings] )
71
71
  complete: ( xhr, status ) -> $uploadForm.trigger( 'ajax:complete', [xhr, status] )
72
72
  success: ( data, status, xhr ) -> $uploadForm.trigger( 'ajax:success', [data, status, xhr] )
73
73
  error: ( xhr, status, error ) -> $uploadForm.trigger( 'ajax:error', [xhr, status, error] )
74
74
 
75
- # $.post(to, content)
76
-
77
75
  data.context.remove() if data.context && settings.remove_completed_progress_bar # remove progress bar
78
76
  $uploadForm.trigger("s3_upload_complete", [content])
79
77
 
@@ -93,7 +91,7 @@ $.fn.S3Uploader = (options) ->
93
91
  if "type" of @files[0]
94
92
  fileType = @files[0].type
95
93
  data.push
96
- name: "Content-Type"
94
+ name: "content-type"
97
95
  value: fileType
98
96
 
99
97
  # substitute upload timestamp and unique_id into key
@@ -115,9 +113,17 @@ $.fn.S3Uploader = (options) ->
115
113
  content.filesize = file.size if 'size' of file
116
114
  content.filetype = file.type if 'type' of file
117
115
  content.unique_id = file.unique_id if 'unique_id' of file
116
+ content.relativePath = build_relativePath(file) if has_relativePath(file)
118
117
  content = $.extend content, settings.additional_data if settings.additional_data
119
118
  content
120
119
 
120
+ has_relativePath = (file) ->
121
+ file.relativePath || file.webkitRelativePath
122
+
123
+ build_relativePath = (file) ->
124
+ file.relativePath || (file.webkitRelativePath.split("/")[0..-2].join("/") + "/" if file.webkitRelativePath)
125
+
126
+
121
127
  #public methods
122
128
  @initialize = ->
123
129
  setUploadForm()
@@ -4,7 +4,7 @@ module S3DirectUpload
4
4
  class Config
5
5
  include Singleton
6
6
 
7
- ATTRIBUTES = [:access_key_id, :secret_access_key, :bucket, :prefix_to_clean, :region]
7
+ ATTRIBUTES = [:access_key_id, :secret_access_key, :bucket, :prefix_to_clean, :region, :url]
8
8
 
9
9
  attr_accessor *ATTRIBUTES
10
10
  end
@@ -17,6 +17,7 @@ module S3DirectUpload
17
17
  aws_secret_access_key: S3DirectUpload.config.secret_access_key,
18
18
  bucket: S3DirectUpload.config.bucket,
19
19
  region: S3DirectUpload.config.region || "s3",
20
+ url: S3DirectUpload.config.url,
20
21
  ssl: true,
21
22
  acl: "public-read",
22
23
  expiration: 10.hours.from_now.utc.iso8601,
@@ -60,7 +61,7 @@ module S3DirectUpload
60
61
  end
61
62
 
62
63
  def url
63
- "http#{@options[:ssl] ? 's' : ''}://#{@options[:region]}.amazonaws.com/#{@options[:bucket]}/"
64
+ @options[:url] || "http#{@options[:ssl] ? 's' : ''}://#{@options[:region]}.amazonaws.com/#{@options[:bucket]}/"
64
65
  end
65
66
 
66
67
  def policy
@@ -75,7 +76,7 @@ module S3DirectUpload
75
76
  ["starts-with", "$key", @options[:key_starts_with]],
76
77
  ["starts-with", "$x-requested-with", ""],
77
78
  ["content-length-range", 0, @options[:max_file_size]],
78
- ["starts-with","$Content-Type",""],
79
+ ["starts-with","$content-type",""],
79
80
  {bucket: @options[:bucket]},
80
81
  {acl: @options[:acl]},
81
82
  {success_action_status: "201"}
@@ -1,3 +1,3 @@
1
1
  module S3DirectUpload
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  namespace :s3_direct_upload do
2
2
  desc "Removes old uploads from specified s3 bucket/directory -- Useful when uploads are processed into another directory"
3
- task :clean_remote_uploads do
3
+ task :clean_remote_uploads => :environment do
4
4
  require 'thread'
5
5
  require 'fog'
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_direct_upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Hoover
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails