Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 218223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:43:50+00:00 2026-05-11T18:43:50+00:00

I am trying to upload a file from a flash widget to my rails

  • 0

I am trying to upload a file from a flash widget to my rails application, which uses attachment_fu to handle uplaoded images. I am using flash to upload since it makes it easy to select and upload multiple files. However, I am getting this error when the rails controller tries to call save! on the newly created ActiveRecord object:

ActiveRecord::RecordInvalid (Validation failed: Content type is not included in the list):
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/validations.rb:946:in `save_without_transactions!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in `transaction'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:120:in `rollback_active_record_state!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:112:in `save!'
    /app/controllers/photos_controller.rb:13:in `create'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'

So, it seems that the content type is not being sent correctly. As a matter of fact, Flash is sending a content type of application/octet-stream, where I would expect it to be image/png (for this particular test case).

My ActionScript 3.0 code that performs the upload looks like this:

var request:URLRequest = new URLRequest(paramObj.serverUrl + "/albums/" + paramObj.albumId + "/photos");
var variables:URLVariables = new URLVariables();
variables["photo[title]"] = file.name;
variables["authenticity_token"] = paramObj.authenticity_token;
variables["commit"] = "Upload Photo";
request.data = variables;
request.method = URLRequestMethod.POST;
file.upload(request, 'photo[uploaded_data]');

The form parameters are all present in the Flash upload that you expect from the regular browser upload. After running a packet sniffer, the only real difference I can see is that the content type is different.

The model uses attachment_fu, andlooks like this:

class Photo < ActiveRecord::Base
  belongs_to :album

  has_attachment :content_type => :image, 
                 :storage => :file_system, 
                 :max_size => 10.megabytes, 
                 :thumbnails => { 
                   :thumb  => '100x100>',  
                   :large  => '800x600>', 
                 } 

  validates_as_attachment
end

So, how can I fix the content type that flash sends? And, why does attachment_fu trust the content type sent by the browser, rather than determining it on its own, using magic numbers or something?

I have noticed that if I remove the :content_type => :image or the validates_as_attachment, or if I change the controller to call save(false), the object gets created, but attachment_fu doesn’t do its job of resizing the image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:43:50+00:00Added an answer on May 11, 2026 at 6:43 pm

    Unfortunately, Flash uploads are always sent with content type “application/octet-stream”. Probably the easiest workaround would be to use mimetype_fu to guess the mimetype in a before_validation callback. Paperclip has this functionality built in.

    Another option is to overwrite is_image? to use your image processor to actually determine whether the file is an image (in rmagick for instance, you can open it and see if it has any layers). This is definitely a more resource-intensive solution but it ensures that you accept all the files you can process and no others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 127k
  • Answers 127k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We removed and recreated the workspace and that fixed it.… May 12, 2026 at 5:34 am
  • Editorial Team
    Editorial Team added an answer The files that the ClickOnce publish create can be run… May 12, 2026 at 5:34 am
  • Editorial Team
    Editorial Team added an answer Let's say 'ID' of your table is 'myTable'. $.getJSON('http://yourpageurl.com', function(data)… May 12, 2026 at 5:34 am

Related Questions

I am trying to find out how to upload a file from a web
I am trying to do a file upload from gwt-ext without bringing up the
i am trying to upload an image from a jsp page using servlet. but
I'm trying to upload a PDF file to a website using Hot Banana's content

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.