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
23cd662e
Commit
23cd662e
authored
Sep 04, 2011
by
Chris Oliver and Prem Sichanugrist
Committed by
Prem Sichanugrist
Sep 04, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use --mime instead of --mime-type for `file` command
Thank you @excid3 for suggestion. Closes #582
parent
cb6efaa5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletions
+18
-1
lib/paperclip/upfile.rb
+1
-1
test/fixtures/text.txt
+1
-0
test/upfile_test.rb
+16
-0
No files found.
lib/paperclip/upfile.rb
View file @
23cd662e
...
...
@@ -25,7 +25,7 @@ module Paperclip
def
type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type
=
(
self
.
original_filename
.
match
(
/\.(\w+)$/
)[
1
]
rescue
"octet-stream"
).
downcase
mime_type
=
(
Paperclip
.
run
(
"file"
,
"-b --mime
-type :file"
,
:file
=>
self
.
path
).
split
(
':'
).
last
.
strip
rescue
"application/x-
#{
type
}
"
)
mime_type
=
(
Paperclip
.
run
(
"file"
,
"-b --mime
:file"
,
:file
=>
self
.
path
).
split
(
/[:;]\s+/
)[
0
]
rescue
"application/x-
#{
type
}
"
)
mime_type
=
"application/x-
#{
type
}
"
if
mime_type
.
match
(
/\(.*?\)/
)
mime_type
end
...
...
test/fixtures/text.txt
View file @
23cd662e
paperclip!
test/upfile_test.rb
View file @
23cd662e
...
...
@@ -34,4 +34,20 @@ class UpfileTest < Test::Unit::TestCase
end
assert_equal
'text/plain'
,
file
.
content_type
end
{
'5k.png'
=>
'image/png'
,
'animated.gif'
=>
'image/gif'
,
'text.txt'
=>
'text/plain'
,
'twopage.pdf'
=>
'application/pdf'
}.
each
do
|
filename
,
content_type
|
should
"return a content type of
#{
content_type
}
from a file command for file
#{
filename
}
"
do
file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
filename
))
class
<<
file
include
Paperclip
::
Upfile
end
assert_equal
content_type
,
file
.
type_from_file_command
end
end
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