pushfile 0.0.1 → 0.0.2

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: f5c2dc724ebfa455539c3017ba2a78f09ec5c7e9
4
- data.tar.gz: d38a730ac57a7fffec72458afca9bd3e1da2bc02
3
+ metadata.gz: 672a79ecf90538535f66127795c40bfc277ce9d2
4
+ data.tar.gz: 186e1726fc0884f7986d0314133039a967e7c07c
5
5
  SHA512:
6
- metadata.gz: b2e7d9724aa09aea4a650ceb9326be8329a9295470a512a8124e200cb28e72b6c07f20f295aabd4a339c3f7c0ff3e2614d3ce0274299670478e66707d8b79c13
7
- data.tar.gz: a70eff1d81494c37b5f4c5ed69fdd1eed3fb099b3667bc8ba954be190fb5c5dadf2b5ced016ef5b540792e6a11ce1e96e95c508c546b3df931da276a0053c2e3
6
+ metadata.gz: 6bb10f4c496d31fee90cdae4c186bacd3b67cd707e047797fb84fc642c11e5d9901e37c3f5651d13dc87c980a790326820945d05da9b9424a0768a15fff3471f
7
+ data.tar.gz: 1c0532d6422f9bc7d53f05efa2082db6a3d967b1bb4d03f0b29599b939fd98f7b81797413f73294d5eadb29d50174ab9cd206d59a0b2a52290a931f66818f37e
@@ -0,0 +1,4 @@
1
+ **Version 0.0.2** - *2017-01-05*
2
+
3
+ - Default mime type if not set
4
+ - Symbols instead of string
data/README.md CHANGED
@@ -25,16 +25,28 @@ Create a config/pushfile.yml for your settings.
25
25
 
26
26
  See [the example pushfile.yml](https://github.com/fugroup/pushfile/blob/master/config/pushfile.yml) for an example.
27
27
 
28
+ If you define an image config, any images you upload will be automatically resized before uploading. You can define both the desired max height and width.
29
+
28
30
  ### Usage
29
31
  For more examples have a look at [the tests for Pushfile.](https://github.com/fugroup/pushfile/blob/master/test/upload_test.rb)
30
32
  ```ruby
31
33
  # Require pushfile if not using Bundler
32
34
  require 'pushfile'
33
35
 
34
- # Create an upload
35
- u = Pushfile::Upload.new
36
+ # Set up a new upload from web server params
37
+ # The Froala editor support is automatic
38
+ u = Pushfile::Upload.new(params)
39
+
40
+ # Ajax upload with progress support, pass the request body StringIO object
41
+ u = Pushfile::Upload.new(params.merge(:stream => request.body))
42
+
43
+ # Set up a new upload from local file
44
+ u = Pushfile::Upload.new(:filename => 'name.jpg', :tempfile => '/tmp/name.jpg')
45
+
46
+ # Upload from remote URL
47
+ u = Pushfile::Upload.new(:url => 'http://fugroup.net/images/fugroup_logo1.png')
36
48
 
37
- # Actually upload file
49
+ # Actually upload file to CDN
38
50
  u.create
39
51
 
40
52
  # Get uploaded url with data
@@ -7,14 +7,14 @@ module Pushfile
7
7
  # Set up data
8
8
  def setup_data
9
9
  # Fetch the image into a tempfile, and store
10
- if @options['url']
10
+ if @options[:url]
11
11
  url_upload
12
12
 
13
- elsif @options['filename']
13
+ elsif @options[:filename]
14
14
  ajax_upload
15
15
 
16
16
  # Do the froala file uploads
17
- elsif @options['file']
17
+ elsif @options[:file]
18
18
  froala_upload
19
19
 
20
20
  end
@@ -22,8 +22,8 @@ module Pushfile
22
22
 
23
23
  # Ajax upload
24
24
  def ajax_upload
25
- filename = @options['filename']
26
- type = @options['mimetype']
25
+ filename = @options[:filename]
26
+ type = @options[:mimetype] || mimetype(filename)
27
27
  file = @options[:tempfile] || "/tmp/upload-#{filename}"
28
28
 
29
29
  # Pass stream (typically request.body) to read chunks
@@ -41,16 +41,16 @@ module Pushfile
41
41
 
42
42
  # Froala upload
43
43
  def froala_upload
44
- tmpfile = @options['file'][:tempfile]
45
- filename = @options['file'][:filename]
46
- type = @options['file'][:type]
44
+ tmpfile = @options[:file][:tempfile]
45
+ filename = @options[:file][:filename]
46
+ type = @options[:file][:type] || mimetype(filename)
47
47
 
48
48
  {:filename => filename, :tempfile => tmpfile, :type => type}
49
49
  end
50
50
 
51
51
  # URL upload
52
52
  def url_upload
53
- url = @options['url'].strip
53
+ url = @options[:url].strip
54
54
 
55
55
  file = Tempfile.new('tmp').tap do |file|
56
56
  file.binmode # must be in binary mode
@@ -58,14 +58,22 @@ module Pushfile
58
58
  file.rewind
59
59
  end
60
60
 
61
+ # Extract the file name from the URL
61
62
  filename = url.split('/').last
62
- extension = filename.split('.').last.downcase rescue ''
63
63
 
64
64
  # Mime type
65
- type = Rack::Mime.mime_type(".#{extension}")
65
+ type = @options[:mimetype] || mimetype(filename)
66
66
 
67
67
  {:filename => filename, :type => type, :tempfile => file}
68
68
  end
69
69
 
70
+ private
71
+
72
+ # Get the mime type from a file name
73
+ def mimetype(path)
74
+ extension = File.basename(path).split('.')[-1]
75
+ Rack::Mime.mime_type(".#{extension}")
76
+ end
77
+
70
78
  end
71
79
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'pushfile'
3
- s.version = '0.0.1'
4
- s.date = '2017-01-08'
3
+ s.version = '0.0.2'
4
+ s.date = '2017-01-11'
5
5
  s.summary = "Pushfile Cloud File Uploader"
6
6
  s.description = "Upload files to Rackspace Cloud or Amazon S3 by URL or file with automatic image resizing."
7
7
  s.authors = ["Fugroup Limited"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-08 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport