当我将图像从 Chrome 发送到 Rails 时,为什么会出现 WebKitFormBoundary 错误?

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

在我的 Google Chrome 扩展中我有:

function submitScreenshot() {
  chrome.tabs.captureVisibleTab(
    null, 
    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>');
      xhr.send(formData);
     }
   );
 }

在我的 Rails 应用程序中,我有:

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.save!
  survey.area.update_columns :screenshot_width => request.filtered_parameters["width"], :screenshot_height => request.filtered_parameters["height"]
  head 200
end

为什么我会收到这个错误?

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

我能够通过删除 JSON 解析尝试并切换到 survey = Survey.find_by(:id => request.filtered_parameters["surveyID"])

来解决这个问题