Comments (12)
Comments from S. Brent Faulkner:
Not directly intended to fix this but a patch I submitted for resolution to #144 adds support for Rack::Mime (if loaded)... this commit adds many extra mime types...
http://github.com/sbfaulkner/paperclip/commit/dd773d20d3fc555f48440c5aa6130af565df448b
from paperclip.
Comments from Sam Stokes:
Relatedly, I needed Paperclip::Upfile to know about the application/pdf MIME type, so this one-line commit 89dcdd50... adds that. It also demonstrates that it's really easy to add new MIME types.
My understanding is that Paperclip::Upfile's ability to guess the content type doesn't normally get used, because if you upload something from a web form, then the browser supplies the content type and Paperclip just uses that. So this mostly comes up during testing (e.g. using webrat to fake out the browser).
Also (sorry for the double post but this might be useful to some people), here's a quick and dirty monkey-patch to stick in a suitable place (like features/support/env.rb
) if you need to quickly add a new content-type.
from paperclip.
Comments from Paul Cortens:
This line of code in storage.rb sets the content-type on S3 to the content-type of the originally uploaded file. If the file has been converted to another image format, this is not accurate.
key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)})
I am guessing that we could use a method similar to content_type in upfile.rb to detect the correct content type from the format specified in the style hash. Or we could have an option to explicitly set the content-type for each style in the style hash.
What do you think?
from paperclip.
I made a fork (http://github.com/korobkov/paperclip), where I I've added support for MIME-type resolution by magic, rather than extension, using http://github.com/minad/mimemagic gem.
It was written on pure ruby, so it will also work on non-posix-compliant systems without /usr/bin/file
utility.
from paperclip.
still no love..
from paperclip.
I've switched MIME-type resolution from http://github.com/minad/mimemagic to http://github.com/Narnach/file_wrapper, which wraps /usr/bin/file...
from paperclip.
I implemented correct content_type detection with file --mime-type command:
http://github.com/monde/paperclip/commit/2ca52df1aa45a8a9cb3d086a6be77168b7f5be52
The file command is able to determine a wide range of content types beyond what is possible with a simple check of a file name's extention.
from paperclip.
monde, I've pulled that last patch into master.
from paperclip.
Thanks! It's better.
But I still not understand, what is the reason to have some MIME-types hardcoded while having content_type detection with file --mime-type
command? Or why not just to rely on some gem-wrapper on file
command (like http://github.com/Narnach/file_wrapper)?
from paperclip.
I assume that @jyurek pulled my feature into the codebase because it maintains the original functionality and provides a reliable back up when the default fails to identify the content-type. Personally I would prefer just delegating the whole thing to the underlying exec of file --mime-type since it is the most all knowing application of this type in the world. The file_wrapper gem is already doing what my patch was doing by calling file --mime-type, but my patch does it in the "Paperclip Way" and in turn doesn't introduce the file_wrapper dependency.
from paperclip.
Basically, what monde said. I may revisit the situation later, however.
from paperclip.
I would not prefer to entirely delegate because using file --mime-type along is getting dangerous.
For example I have two perfectly valid mp3s, one is correctly identified by the file command as audio/mpeg, the other one as application/octet-stream.
I checked for a new version of file command but it doesn't resolve the issue.
from paperclip.
Related Issues (20)
- Upload file apk to s3 HOT 1
- AWS::S3::Errors::NoSuchKey No Such Key
- Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for: HOT 3
- How to store original in different storage bucket?
- PaperClip 2.8 - Rails 2.3 - Ruby 1.87 - OpenSSL::SSL::SSLError (SSL_read:: shutdown while in init): HOT 2
- With Ruby 3.0 validator produces "ArgumentError: wrong number of arguments (given 3, expected 1..2)" HOT 6
- Paperclip mimemagic dependency licensing implication HOT 11
- Transfer ownership of gem to Kreeti HOT 3
- Generate s3 bucket key from DB records
- Migrate to ActiveStorage without re-uploading files?
- default_url is always hit with a HTTP request
- Paperclip::AdapterRegistry::NoHandlerError:
- "attachment" type migration error in Rails 7 HOT 5
- Uploading same attachment twice.
- Uploading same attachment twice fails until i refresh the ui after first upload.
- *_file_name attribute without extension
- Webp image upload issue HOT 2
- use file -b --mime 'test.json' have problem in AWS linux 2
- ContentTypeDetector false positive from Mime HOT 1
- s3 deprecating TLS 1.1 and moving to default TLS 1.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paperclip.