pushfile 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -3
- data/lib/pushfile/data.rb +19 -11
- data/pushfile.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 672a79ecf90538535f66127795c40bfc277ce9d2
|
4
|
+
data.tar.gz: 186e1726fc0884f7986d0314133039a967e7c07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bb10f4c496d31fee90cdae4c186bacd3b67cd707e047797fb84fc642c11e5d9901e37c3f5651d13dc87c980a790326820945d05da9b9424a0768a15fff3471f
|
7
|
+
data.tar.gz: 1c0532d6422f9bc7d53f05efa2082db6a3d967b1bb4d03f0b29599b939fd98f7b81797413f73294d5eadb29d50174ab9cd206d59a0b2a52290a931f66818f37e
|
data/CHANGELOG.md
CHANGED
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
|
-
#
|
35
|
-
|
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
|
data/lib/pushfile/data.rb
CHANGED
@@ -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[
|
10
|
+
if @options[:url]
|
11
11
|
url_upload
|
12
12
|
|
13
|
-
elsif @options[
|
13
|
+
elsif @options[:filename]
|
14
14
|
ajax_upload
|
15
15
|
|
16
16
|
# Do the froala file uploads
|
17
|
-
elsif @options[
|
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[
|
26
|
-
type = @options[
|
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[
|
45
|
-
filename = @options[
|
46
|
-
type = @options[
|
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[
|
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 =
|
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
|
data/pushfile.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'pushfile'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2017-01-
|
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.
|
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-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|