Using file_column and sending correct content type

Hi, I'm using file_column to save images to the file system. To protect the images, I'm uploading to a non-publicly accessible directory. Therefore, I'm using a controller method to send the file when requested:

  def get_pic
     @fctrial = Fctrial.find(params[:id])
     send_file(@fctrial.image, {:disposition => 'inline', :type => 'image/jpeg'})
  end

As you can see, I'm setting the :type to 'image/jpeg' so obviously this is not correct for image/png or image/gif. How do I get to send the correct content type? Should I save the content type in the database also? Is there some simpler way?

Thanks,
Mohit.

You could inspect the filename and use that to figure out what type of file.

Like:

type = ‘image/gif’ if @fctrial[‘image’] =~ /gif$/
(I don’t know if the regex is correct)

Greg Gross wrote:

You could inspect the filename and use that to figure out what type of file.

Like:

type = 'image/gif' if @fctrial['image'] =~ /gif$/
(I don't know if the regex is correct)

Thanks, Greg! That should work.. I was just wondering if file_column stored that information somewhere.. cos, obviously, it knows when the file is uploaded! :smiley:

Cheers
Mohit.