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
8c7c1e89
Commit
8c7c1e89
authored
Apr 26, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handling the file command, added after the initial rails3 branch.
parent
488ffd25
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
lib/paperclip/upfile.rb
+4
-1
test/upfile_test.rb
+2
-2
No files found.
lib/paperclip/upfile.rb
View file @
8c7c1e89
...
@@ -16,7 +16,10 @@ module Paperclip
...
@@ -16,7 +16,10 @@ module Paperclip
when
"js"
then
"application/js"
when
"js"
then
"application/js"
when
"csv"
,
"xml"
,
"css"
then
"text/
#{
type
}
"
when
"csv"
,
"xml"
,
"css"
then
"text/
#{
type
}
"
else
else
Paperclip
.
run
(
"file"
,
"--mime-type
#{
self
.
path
}
"
).
split
(
':'
).
last
.
strip
rescue
"application/x-
#{
type
}
"
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
content_type
=
(
Paperclip
.
run
(
"file"
,
"--mime-type
#{
self
.
path
}
"
).
split
(
':'
).
last
.
strip
rescue
"application/x-
#{
type
}
"
)
content_type
=
"application/x-
#{
type
}
"
if
content_type
.
match
(
/\(.*?\)/
)
content_type
end
end
end
end
...
...
test/upfile_test.rb
View file @
8c7c1e89
...
@@ -23,6 +23,8 @@ class UpfileTest < Test::Unit::TestCase
...
@@ -23,6 +23,8 @@ class UpfileTest < Test::Unit::TestCase
assert_equal
content_type
,
file
.
content_type
assert_equal
content_type
,
file
.
content_type
end
end
end
end
should
"return a content_type of text/plain on a real file whose content_type is determined with the file command"
do
should
"return a content_type of text/plain on a real file whose content_type is determined with the file command"
do
file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"LICENSE"
))
file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"LICENSE"
))
...
@@ -31,6 +33,4 @@ class UpfileTest < Test::Unit::TestCase
...
@@ -31,6 +33,4 @@ class UpfileTest < Test::Unit::TestCase
end
end
assert_equal
'text/plain'
,
file
.
content_type
assert_equal
'text/plain'
,
file
.
content_type
end
end
end
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