Forum: Ruby on Rails upload problem with mimetypes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
51f10739fd903d3b57561a15e4598954?d=identicon&s=25 M Daggett (Guest)
on 2005-12-16 23:03
(Received via mailing list)
I am building a flash-based uploader for rails that allows multiple
files to be selected from a user's hard drive and then put into a
queue for upload. This works great except that macromedia uploads
everything as "application/octet-stream". This means that displaying
the newly uploaded content inline is a pain because the browser asks
to download it first.

To get around this I am finding the file extension and overriding the
content_type variable with my new variable from a look up list for
example "jpg" would then use image/jpeg. This works well with most
images however some do not display correctly and I get this error:

def find_flash_upload_mime_type (ext)
  re = /(\.)/
  md = re.match(ext)
  type = case md.post_match.downcase
             when "jpg" : "image/jpeg"
             ... more case statements for other file types ...
             else "application/octet-stream"
  end
  return type
end

The image "http://localhost:3000/asset/show_data/120" cannot be
displayed, because it contains errors.

Though if I set the content_type back to "application/octet-stream"
and download it the file opens fine.

Does anyone know why this is happening?

Thanks,
Mark
--
This topic is locked and can not be replied to.