filestack/filestack-ruby

NoMethodError when mime type is unknown

ryoung opened this issue · 2 comments

With the replacement of mimemagic with mini_mime in #82, we're encountering a NoMethodError (undefined method 'content_type' for nil:NilClass) on file uploads where the mime type cannot be detected by the mini_mime gem.

Looking at the filestack-ruby code, it looks like you're assuming MiniMime.lookup_by_filename will always return a value, but this is not always the case.

We have the same problem.

tempfile = Tempfile.new('test.txt')
uploader = FilestackClient.new(Rails.configuration.filestack_rails.api_key)

uploader.upload(filepath: tempfile.path, options: {})

# => NoMethodError (undefined method `content_type' for nil:NilClass)

We made a workaround by defining mimetype in options with the value FilestackConfig::DEFAULT_UPLOAD_MIMETYPE as a temporary solution.

uploader.upload(filepath: tempfile.path, options: { mimetype: FilestackConfig::DEFAULT_UPLOAD_MIMETYPE })

But probably would be better to keep the behaviour from the previous version.

@ryoung @tomaskubala Thank you for letting us know and for this PR. I've just merged it.