Determine file type in Ruby

There is a ruby binding to libmagic that does what you need. It is available as a gem named ruby-filemagic: gem install ruby-filemagic Require libmagic-dev. The documentation seems a little thin, but this should get you started: $ irb irb(main):001:0> require ‘filemagic’ => true irb(main):002:0> fm = FileMagic.new => #<FileMagic:0x7fd4afb0> irb(main):003:0> fm.file(‘foo.zip’) => “Zip archive … Read more

Difference between application/x-javascript and text/javascript content types

The JavaScript MIME Type When sending JavaScript content, you should use text/javascript as per RFC 9239. Aliases application/javascript, application/x-javascript, text/javascript1.0, text/javascript1.1, text/javascript1.2, text/javascript1.3, text/javascript1.4, text/javascript1.5, text/jscript, and text/livescript are deprecated aliases for it. If you are writing a tool which consumes JavaScript (e.g. an HTTP client) then you should consider supporting them for backwards compatibility. … Read more

Jquery ignores encoding ISO-8859-1

Because I had the same problem, I’ll provide a solution that worked for me. Background: Microsoft Excel is too stupid to export a CSV-File in charset UTF-8: $.ajax({ url: ‘…’, contentType: ‘Content-type: text/plain; charset=iso-8859-1’, // This is the imporant part!!! beforeSend: function(jqXHR) { jqXHR.overrideMimeType(‘text/html;charset=iso-8859-1’); } });

Avoiding content type issues when downloading a file via browser on Android

To make any downloads work on all (and especially older) Android versions as expected, you need to… set the ContentType to application/octet-stream put the Content-Disposition filename value in double quotes write the Content-Disposition filename extension in UPPERCASE Read my blog post for more details: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/

Can’t send a post request when the ‘Content-Type’ is set to ‘application/json’

It turns out that CORS only allows some specific content types. The only allowed values for the Content-Type header are: application/x-www-form-urlencoded multipart/form-data text/plain Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS To set the content type to be ‘application/json’, I had to set a custom content type header in the API. Just removed the last header and added this one: ->header(‘Access-Control-Allow-Headers’, … Read more