NameError: uninitialized constant MIME

This line of rubypress code:

:type => MIME::Types.type_for(FILENAME).first.to_s,

is barfing with the following error:

Read More
NameError: uninitialized constant MIME

The whole block is:

FILENAME='myFile.png'
wp.uploadFile(:data => {
    :name => FILENAME,
    :type => MIME::Types.type_for(FILENAME).first.to_s,
    :bits => XMLRPC::Base64.new(IO.read(FILENAME))
    })

Any suggestions what the problem is?

Related posts

3 comments

  1. extension =  File.extname(file).split(".")[1]
    Mime::Type.lookup_by_extension(extension)
    
  2. A little late to the party.

    After a recent Ruby upgrade, I’ve found that MIME::TYPES could not be initialized. A more modern solution is to use marcel, which is already included as a dependency with the recent rails version.

    Marcel::MimeType.for(file)
    

Comments are closed.