Why the WebKitFormBoundary error when I send an image from Chrome to Rails?

In my Google Chrome Extension I have:

function submitScreenshot() {
    function(img) {
      var xhr = new XMLHttpRequest(), formData = new FormData();  
      formData.append("img", img);
      formData.append("height", localStorage["tabHeight"]);
      formData.append("width", localStorage["tabWidth"]);
      formData.append("surveyID", localStorage["ID"]);
      xhr.open("POST", "http://localhost:3000/task/screenshot", true);
      xhr.setRequestHeader('Authorization', 'Token token=<redacted>');

In my Rails app I have:

def screenshot
  response = JSON.parse(request.body.read.html_safe)
  img = request.filtered_parameters["img"]
  survey = Survey.find_by(:id => response["surveyID"])
  survey.area.screenshot = img
  survey.area.update_columns :screenshot_width => request.filtered_parameters["width"], :screenshot_height => request.filtered_parameters["height"]
  head 200

Why then am I getting this error?

JSON::ParserError (757: unexpected token at '------WebKitFormBoundary6BJ6BvfXeLjByMbN


I was able to fix this by deleting the attempt at JSON parsing and switching to survey = Survey.find_by(:id => request.filtered_parameters["surveyID"])

Need Your Help

achartengine - different colors for different points and lines

android charts line achartengine

I'm using AChartEngine to visualize measurement values in a line chart view. The visualization itself works already however one important part is missing and I have no idea how to implement it. Each

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.