Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: uninitialized constant MIME

This line of rubypress code:

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

is barfing with the following error:

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?

like image 767
Snowcrash Avatar asked Feb 23 '26 03:02

Snowcrash


2 Answers

Add require 'mime/types' to the top of your file.

like image 177
Nathan Avatar answered Feb 25 '26 15:02

Nathan


extension =  File.extname(file).split(".")[1]
Mime::Type.lookup_by_extension(extension)
like image 44
Jack Kinsella Avatar answered Feb 25 '26 16:02

Jack Kinsella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!