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
02d99ec3
Commit
02d99ec3
authored
Apr 15, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #829 from kir/master
Fix problem with incorrect content_type from `file` command
parents
05a23718
3e98fc2e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletions
+8
-1
lib/paperclip/io_adapters/file_adapter.rb
+1
-1
test/file_adapter_test.rb
+7
-0
No files found.
lib/paperclip/io_adapters/file_adapter.rb
View file @
02d99ec3
...
...
@@ -69,7 +69,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 :file"
,
:file
=>
self
.
path
).
split
(
/[:;
]\s
+/
)[
0
]
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/file_adapter_test.rb
View file @
02d99ec3
...
...
@@ -20,6 +20,13 @@ class FileAdapterTest < Test::Unit::TestCase
assert_equal
"image/png"
,
@subject
.
content_type
end
should
"provide correct mime-type for empty file"
do
@subject
=
Paperclip
.
io_adapters
.
for
(
Tempfile
.
new
(
"file_adapter_test"
))
# Content type contained '\n' at the end, for an empty file, on my Mac
assert_equal
"application/x-empty"
,
@subject
.
content_type
end
should
"get the file's size"
do
assert_equal
4456
,
@subject
.
size
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