简体   繁体   English

jQuery文件上传ActionController :: UnknownFormat

[英]jQuery File Upload ActionController::UnknownFormat

I'm trying to upload multiple pictures using jquery-fileupload-rails 我正在尝试使用jquery-fileupload-rails上传多张图片

Here is my javascript for doing it: 这是我的Java脚本:

<script type="text/javascript" charset="utf-8">
  $(function () {
      // Initialize the jQuery File Upload widget:
      $('#fileupload').fileupload({
        paramName: 'album_picture[picture]'
      });
      // 
      // Load existing files:
      $.getJSON($('#fileupload').prop('action'), function (files) {
        var fu = $('#fileupload').data('blueimpFileupload'), 
          template;
        fu._adjustMaxNumberOfFiles(-files.length);
        console.log(files);
        template = fu._renderDownload(files)
          .appendTo($('#fileupload .files'));
        // Force reflow:
        fu._reflow = fu._transition && template.length &&
          template[0].offsetWidth;
        template.addClass('in');
        $('#loading').remove();
      });

  });
</script>

Here is the request headers: 这是请求标头:

POST /album_pictures HTTP/1.1
Host: 127.0.0.1:3000
Connection: keep-alive
Content-Length: 98937
Accept: undefined
Origin: http://127.0.0.1:3000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFhpKR7ztl9s9QWAZ
Referer: http://127.0.0.1:3000/album_pictures/new/3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4

Here is the request params: 这是请求参数:

{"utf8"=>"✓", "authenticity_token"=>"xXkbJNMVVNy3SocUJKKHHts0RO8PEP8aGqw8C+dlaKw=", "album_picture"=>{"album_id"=>"3", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007fac660e8c28 @tempfile=#<Tempfile:/var/folders/_7/jc0746b936q9b3q3lsf7xj7m0000gn/T/RackMultipart20131217-71351-1csiua>, @original_filename="gall1_big5.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"album_picture[picture]\"; filename=\"gall1_big5.jpg\"\r\nContent-Type: image/jpeg\r\n">}}

I keep getting the following: 我不断收到以下信息:

ActionController::UnknownFormat (ActionController::UnknownFormat):
  app/controllers/album_pictures_controller.rb:49:in `create'

 respond_to do |format|

Here is my controller code: 这是我的控制器代码:

def create
    @album_picture = AlbumPicture.new(album_picture_params)

    respond_to do |format|
      if @album_picture.save
        format.html {
          render :json => [@album_picture.to_jq_upload].to_json,
          :content_type => 'text/html',
          :layout => false
        }
        format.json { render json: {files: [@album_picture.to_jq_upload]}, status: :created, location: @album_picture }
      else
        format.html { render action: "new" }
        format.json { render json: @album_picture.errors, status: :unprocessable_entity }
      end
    end
  end

The problem is in your controller your respond_to block isn't formatted properly. 问题出在您的控制器中,您的response_to块的格式不正确。 Post that code if you want a more specific answer. 如果您需要更具体的答案,请发布该代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM