Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
9ecd52ea
Commit
9ecd52ea
authored
Apr 26, 2015
by
Stephen Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some style guide issues
parent
2a0274d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
lib/paperclip/content_type_detector.rb
+7
-5
lib/paperclip/file_command_content_type_detector.rb
+1
-1
spec/paperclip/content_type_detector_spec.rb
+2
-1
No files found.
lib/paperclip/content_type_detector.rb
View file @
9ecd52ea
...
...
@@ -54,24 +54,26 @@ module Paperclip
end
def
calculated_type_matches
possible_types
.
select
{
|
content_type
|
content_type
==
type_from_file_contents
}
possible_types
.
select
do
|
content_type
|
content_type
==
type_from_file_contents
end
end
def
type_from_file_contents
type
=
begin
type_from_mime_magic
||
type_from_file_command
rescue
Errno
::
ENOENT
=>
e
Paperclip
.
log
(
"Error while determining content type:
#{
e
}
"
)
SENSIBLE_DEFAULT
end
end
def
type_from_file_command
@type_from_file_command
||=
FileCommandContentTypeDetector
.
new
(
@filename
).
detect
@type_from_file_command
||=
FileCommandContentTypeDetector
.
new
(
@filename
).
detect
end
def
type_from_mime_magic
@type_from_mime_magic
||=
MimeMagic
.
by_magic
(
File
.
open
(
@filename
)).
try
(
:type
)
@type_from_mime_magic
||=
MimeMagic
.
by_magic
(
File
.
open
(
@filename
)).
try
(
:type
)
end
end
end
lib/paperclip/file_command_content_type_detector.rb
View file @
9ecd52ea
...
...
@@ -13,8 +13,8 @@ module Paperclip
private
def
type_from_file_command
type
=
begin
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type
=
begin
Paperclip
.
run
(
"file"
,
"-b --mime :file"
,
file:
@filename
)
rescue
Cocaine
::
CommandLineError
=>
e
Paperclip
.
log
(
"Error while determining content type:
#{
e
}
"
)
...
...
spec/paperclip/content_type_detector_spec.rb
View file @
9ecd52ea
...
...
@@ -19,7 +19,8 @@ describe Paperclip::ContentTypeDetector do
it
'returns content type of file if it is an acceptable type'
do
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'application/mp4'
),
MIME
::
Type
.
new
(
'video/mp4'
),
MIME
::
Type
.
new
(
'audio/mp4'
)])
Paperclip
::
ContentTypeDetector
.
any_instance
.
stubs
(
:type_from_file_contents
).
returns
(
"video/mp4"
)
Paperclip
::
ContentTypeDetector
.
any_instance
.
stubs
(
:type_from_file_contents
).
returns
(
"video/mp4"
)
@filename
=
"my_file.mp4"
assert_equal
"video/mp4"
,
Paperclip
::
ContentTypeDetector
.
new
(
@filename
).
detect
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment