Skip to content

[Bug] Cannon .CR2 file is not properly detected #141

@bogdan

Description

@bogdan

The following file is not properly detected as image/x-canon-cr2:

https://realphotos.mypinata.cloud/ipfs/bafybeihzvorkcgtcg6yxgnhof7ifvqguf2yuvtko34shgxgz6eqdvpxlxq

Reference shell:

URL="http://silver-naval-alligator-759.mypinata.cloud/files/bafybeihzvorkcgtcg6yxgnhof7ifvqguf2yuvtko34shgxgz6eqdvpxlxq"; mime_head=$(curl -sI "$URL" | grep -i "^content-type:" | awk '{print $2}' | tr -d '\r'); [ -n "$mime_head" ] && echo "$mime_head" || { tmp=$(mktemp); curl -s --range 0-4095 "$URL" -o "$tmp"; file --mime-type -b "$tmp"; rm -f "$tmp"; }
# => image/x-canon-cr2

Reproduce script:

#!/usr/bin/env ruby

require 'open-uri'
require 'marcel'

url = "http://silver-naval-alligator-759.mypinata.cloud/files/bafybeihzvorkcgtcg6yxgnhof7ifvqguf2yuvtko34shgxgz6eqdvpxlxq"

io = URI.open(url, "rb", content_length_proc: ->(len) { puts "Fetching #{len} bytes..." if len })
head = io.read(4096)
io.rewind

mime_type = Marcel::MimeType.for(StringIO.new(head), name: File.basename(url))
puts "Detected MIME type: #{mime_type}"

Output:

Detected MIME type: image/tiff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions