rack-raw-upload 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -2
- data/lib/rack-raw-upload.rb +1 -0
- data/lib/rack/raw_upload.rb +9 -2
- data/test/raw_upload_test.rb +8 -1
- metadata +18 -4
data/README.md
CHANGED
@@ -19,18 +19,31 @@ Rack::RawUpload expects that requests will:
|
|
19
19
|
|
20
20
|
## Configuration
|
21
21
|
|
22
|
-
|
22
|
+
### Bog-standard Rack app
|
23
23
|
|
24
|
+
The simpler case. Add these lines in your `config.ru`, where appropriate:
|
25
|
+
|
26
|
+
require 'rack/raw_upload'
|
24
27
|
use Rack::RawUpload
|
25
28
|
|
26
29
|
If you want to limit the conversion to a few known paths, do:
|
27
30
|
|
31
|
+
require 'rack/raw_upload'
|
28
32
|
use Rack::RawUpload, :paths => ['/upload/path', '/alternative/path.*']
|
29
33
|
|
30
34
|
You can also make it so that the conversion only happens when explicitly required by the client using a header. This would be `X-File-Upload: true` to make the conversion regardless of the content type. A value of `X-File-Upload: smart` would ask for the normal detection to be performed. For this, use the following setting:
|
31
35
|
|
32
36
|
use Rack::RawUpload, :explicit => true
|
33
37
|
|
38
|
+
### Ruby on Rails
|
39
|
+
|
40
|
+
Add this to your Gemfile
|
41
|
+
|
42
|
+
gem 'rack-raw-upload'
|
43
|
+
|
44
|
+
and then add the middleware in application.rb
|
45
|
+
|
46
|
+
config.middleware.use 'Rack::RawUpload'
|
34
47
|
|
35
48
|
## More options
|
36
49
|
|
@@ -50,4 +63,6 @@ When present, Rack::RawUpload will assume that the header ***`X-Query-Params`***
|
|
50
63
|
|
51
64
|
A blog post on HTML5 uploads, which are raw uploads, and can be greatly simplified with this middleware:
|
52
65
|
|
53
|
-
* [http://blog.new-bamboo.co.uk/2010/7/30/html5-powered-ajax-file-uploads](http://blog.new-bamboo.co.uk/2010/7/30/html5-powered-ajax-file-uploads)
|
66
|
+
* [http://blog.new-bamboo.co.uk/2010/7/30/html5-powered-ajax-file-uploads](http://blog.new-bamboo.co.uk/2010/7/30/html5-powered-ajax-file-uploads)
|
67
|
+
|
68
|
+
This middleware should work with Ruby 1.8.7, 1.9.2, REE, Rubinius and JRuby. Tests for all these platforms are run on the wonderful [Travis-CI](http://travis-ci.org/) regularly, and the current status of these is: [![Build Status](http://travis-ci.org/newbamboo/rack-raw-upload.png)](http://travis-ci.org/newbamboo/rack-raw-upload)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/raw_upload'
|
data/lib/rack/raw_upload.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'tmpdir' # Needed in 1.8.7 to access Dir::tmpdir
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
class RawUpload
|
3
5
|
|
4
|
-
VERSION = '1.0.
|
6
|
+
VERSION = '1.0.4'
|
5
7
|
|
6
8
|
def initialize(app, opts = {})
|
7
9
|
@app = app
|
@@ -80,7 +82,12 @@ module Rack
|
|
80
82
|
end
|
81
83
|
|
82
84
|
def content_type_of_raw_file?(content_type)
|
83
|
-
|
85
|
+
case content_type
|
86
|
+
when %r{^application/x-www-form-urlencoded}, %r{^multipart/form-data}
|
87
|
+
false
|
88
|
+
else
|
89
|
+
true
|
90
|
+
end
|
84
91
|
end
|
85
92
|
end
|
86
93
|
end
|
data/test/raw_upload_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rack/test'
|
3
3
|
require 'shoulda'
|
4
|
-
require 'rack
|
4
|
+
require 'rack-raw-upload'
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
class RawUploadTest < Test::Unit::TestCase
|
@@ -52,6 +52,13 @@ class RawUploadTest < Test::Unit::TestCase
|
|
52
52
|
upload('CONTENT_TYPE' => 'multipart/form-data')
|
53
53
|
assert_successful_non_upload
|
54
54
|
end
|
55
|
+
|
56
|
+
# "stuff" should be something like "boundary=----WebKitFormBoundaryeKPeU4p65YgercgO",
|
57
|
+
# but if I do that here, Rack tries to be clever and the test breaks
|
58
|
+
should "not work with Content-Type 'multipart/form-data; stuff'" do
|
59
|
+
upload('CONTENT_TYPE' => 'multipart/form-data; stuff')
|
60
|
+
assert_successful_non_upload
|
61
|
+
end
|
55
62
|
|
56
63
|
should "be forced to perform a file upload if `X-File-Upload: true`" do
|
57
64
|
upload('CONTENT_TYPE' => 'multipart/form-data', 'HTTP_X_FILE_UPLOAD' => 'true')
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-raw-upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Pablo Brasero
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
+
date: 2011-06-07 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: json
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -33,9 +36,11 @@ dependencies:
|
|
33
36
|
name: rake
|
34
37
|
prerelease: false
|
35
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
36
40
|
requirements:
|
37
41
|
- - ">="
|
38
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
39
44
|
segments:
|
40
45
|
- 0
|
41
46
|
version: "0"
|
@@ -45,9 +50,11 @@ dependencies:
|
|
45
50
|
name: rack-test
|
46
51
|
prerelease: false
|
47
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
48
54
|
requirements:
|
49
55
|
- - ">="
|
50
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
51
58
|
segments:
|
52
59
|
- 0
|
53
60
|
version: "0"
|
@@ -57,9 +64,11 @@ dependencies:
|
|
57
64
|
name: shoulda
|
58
65
|
prerelease: false
|
59
66
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
60
68
|
requirements:
|
61
69
|
- - ">="
|
62
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
63
72
|
segments:
|
64
73
|
- 0
|
65
74
|
version: "0"
|
@@ -76,6 +85,7 @@ extra_rdoc_files:
|
|
76
85
|
- README.md
|
77
86
|
files:
|
78
87
|
- lib/rack/raw_upload.rb
|
88
|
+
- lib/rack-raw-upload.rb
|
79
89
|
- test/raw_upload_test.rb
|
80
90
|
- LICENSE
|
81
91
|
- README.md
|
@@ -93,23 +103,27 @@ rdoc_options:
|
|
93
103
|
require_paths:
|
94
104
|
- lib
|
95
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
96
107
|
requirements:
|
97
108
|
- - ">="
|
98
109
|
- !ruby/object:Gem::Version
|
110
|
+
hash: 3
|
99
111
|
segments:
|
100
112
|
- 0
|
101
113
|
version: "0"
|
102
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
103
116
|
requirements:
|
104
117
|
- - ">="
|
105
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
106
120
|
segments:
|
107
121
|
- 0
|
108
122
|
version: "0"
|
109
123
|
requirements: []
|
110
124
|
|
111
125
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.3.
|
126
|
+
rubygems_version: 1.3.7
|
113
127
|
signing_key:
|
114
128
|
specification_version: 3
|
115
129
|
summary: Rack Raw Upload middleware
|