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

  • SEARCH
  • Home
  • 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 680417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:22:13+00:00 2026-05-14T01:22:13+00:00

Possible Duplicate: Weird “406 not acceptable” error following code generate a 406 Not Acceptable

  • 0

Possible Duplicate:
Weird “406 not acceptable” error

following code generate a 406 Not Acceptable error.

What can be wrong with my code?

  def remote_create
    @photo = Photo.new(params[:photo])

    respond_to do |format|
      if @photo.save
        # add @photo's thumbnail to last import tag
        format.js {
          render :update do |page|
            page.insert_html :bottom, 'polaroids' , :partial    => 'polaroid', :locals => {:photo => @photo}
          end 
        }
      else
        format.html
      end
    end
  end


Started POST "/photos/remote_create" for 127.0.0.1 at 2010-03-14 14:02:08
  Processing by PhotosController#remote_create as HTML
  Parameters: {"photo"=>{"photo"=>#<File:/var/folders/BT/BTpdsWBkF6myaI-sl3+1NU+++TI/-Tmp-/RackMultipart20100314-285-1y9eq1x-0>, "name"=>"4204497503_a0c43c561d.jpg"}}
  SQL (0.6ms)  INSERT INTO "photos" ("created_at", "filename", "height", "name", "photo_content_type", "photo_file_name", "photo_file_size", "photo_updated_at", "size", "updated_at", "width") VALUES ('2010-03-14 13:02:08.449499', NULL, NULL, '4204497503_a0c43c561d.jpg', 'application/octet-stream', '4204497503_a0c43c561d.jpg', 136710, '2010-03-14 13:02:08.446370', NULL, '2010-03-14 13:02:08.449499', NULL)
[paperclip] Saving attachments.
[paperclip] saving /Users/denisjacquemin/Documents/code/projects/photos/public/system/photos/224/original/4204497503_a0c43c561d.jpg
Completed in 101ms with 406

here is the request header

Host    localhost:3000
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Content-Type    multipart/form-data; boundary=AJAX-----------------------1268573300187
Referer http://localhost:3000/photos/
Content-Length  2058592
Cookie  remember_token=ea5af5a7c9a38d72bfd07756754af682a5d16cac; _photos_session=BAh7ByIQX2NzcmZfdG9rZW4iMW1yTUo3RkhzRlhPUXhsa0ptdDAyaUpDcXlTdlU0OHk2WHJhUzBzMmVQV1k9Ig9zZXNzaW9uX2lkIiViNzc0MGI2ZGMyYWNlNjEzZWEwYjVhM2U1Njg1MWE3YQ%3D%3D--1af96dbdbef595c48121e4f5c16298cadeef5b2a
  • 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-14T01:22:14+00:00Added an answer on May 14, 2026 at 1:22 am

    I found the solution, when I build the ajax request, I need to set the following header parameter

    xhr.setRequestHeader("Accept", "text/javascript");
    

    before setting this parameter, the request header was

    Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    

    and now the request header looks like this

    Accept  text/javascript
    

    works fine now

    UPDATE for goo:

    Here is the full code, the setRequestHeader is in the send function

    hope it helps

    In my view

    <%= link_to 'upload all', '/photos/remote_create', :remote => true, :method => 'POST', :multipart => 'droppedItems', :id => 'upload', :class => 'awesome small green' %>
    

    In rails.js function handleRemote(element)

    else if (element.readAttribute('multipart') != null) {
      url    = element.readAttribute('data-url') || element.readAttribute('href');
      var uploader = new Uploader(null, $(element.readAttribute('multipart')));
      uploader.sendFiles(url);
      return;
    }
    

    In a js utility file

    sendFiles : function(url) {
        try {
          this.filesToUpload.forEach(function(file, index, all) {
              send(file, url);
          });
        } catch(e) {
            alert('send Error: ' + e);
        }
    }
    
    function send(file, url) {
        try {
            var xhr = new XMLHttpRequest;
    
            var boundary    = generateBoundary();
    
            var contentType = "multipart/form-data; boundary=" + boundary;
    
            xhr.upload.addEventListener("loadstart", (function(e){
                $('progress_'+file.name).update('0%');
            }), false);
    
            xhr.upload.addEventListener("progress", (function(e) {
                  if (e.lengthComputable) {
                      var percentage = Math.round((e.loaded * 100) / e.total);
                      $('progress_'+file.name).update(percentage + '%');
                  }
            }), false);
    
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    eval(xhr.responseText || '');
                }
            };
    
            xhr.open("POST", url, true);
    
            xhr.setRequestHeader("Content-Type", contentType);
            xhr.setRequestHeader("Accept", "text/javascript");
    
            var CRLF  = "\r\n";
            var request = "--" + boundary  + CRLF;
    
            request += 'Content-Disposition: form-data; ';
            request += 'name="' + 'photo[name]' + '"' + CRLF + CRLF;
            request += file.name + CRLF;
    
            request += "--" + boundary + CRLF;
    
            request += 'Content-Disposition: form-data; ';
            request += 'name="' + 'photo[photo]' + '"; ';
            request += 'filename="'+ file.fileName + '"' + CRLF;
    
            request += "Content-Type: application/octet-stream" + CRLF + CRLF;
            request += file.value + CRLF;
            request+= "--" + boundary + "--" + CRLF;
    
            xhr.sendAsBinary(request);
    
        } catch(e) {
            alert('send Error: ' + e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 414k
  • Answers 415k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I just created a project. It has an ASP.NET HttpHandler… May 15, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer You can but not in that way. this is referred… May 15, 2026 at 8:51 am
  • Editorial Team
    Editorial Team added an answer You're looking for an UpDown control, also called a spinbox.… May 15, 2026 at 8:51 am

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.