2014-07-21 29 views
0

我按照Transloadit Rails GitHub page上的教程進行了操作,但無法在未收到警報的情況下提交表單:Could not find input[name=params] in your form。點擊「確定」後,Transloadit會立即拋出INVALID_FORM_DATA: bad form data, cannot parse,數據永遠不會打到我的服務器。無法在Rails 4中使用Transloadit上傳照片

我的應用程序正在使用Rails 4.1.4jquery-rails 2.1.4

這裏是我的形式:

= form_for @profile, url: community_add_photo_path(@profile), html: {id: 'photo_form'} do |f| 
    = render 'shared/error_messages', object: f.object 
    = transloadit :profile_photo 
    = hidden_field_tag 'transloadit_template', 'profile_photo' 

    %table.list 
    %tr 
     %td.faded.label Photo Filename 
     %td= f.file_field :photo, required: true 
    %tr 
     %td 
     %td= f.submit 'Upload' 

= transloadit_jquerify :photo_form, wait: true 

而且我transloadit.yml文件:

development: 
    jquery_sdk_version: 'latest' 
    auth: 
    key:  'key' 
    secret: 'secret' 
    duration: 1800 # 30 minute validity period for signed upload forms 

    templates: 
    profile_photo: 
     steps: 
     resize: 
      height: 256 
      resize_strategy: 'fillcrop' 
      robot: '/image/resize' 
      width: 256 
     store: 
      bucket: 'bucket-name' 
      key: 'key' 
      path: 'temp/${assembly.id}/${file.name}' 
      robot: '/s3/store' 
      secret: 'secret' 

有什麼建議?謝謝!

回答

0

我假設你在控制器中有params解碼器。這是我有,它的工作,但現在要使用jQuery,因爲我不能控制發生了什麼。

 = bootstrap_form_for apr, :remote=> true, html: { :id => "showapr#{apr.id}" , "data-type" => :json, class: 'form-horizontal' } do |f| 
      = hidden_field_tag :eventid, apr.event.id 
      = transloadit :video_encode 
      .fileupload.fileupload-new.pull-left{"data-provides" => "fileupload", style: "padding-right: 5px;"} 
       .fileupload-preview.thumbnail{:style => "width: 140px; height: 140px;"} 
        - if apr.upload.present? 
         - if apr.upload["thumbs"].present? 
          %img{ :src => apr.upload["thumbs"][0], :style => "width: 140px;height: 140px;"} 
        -else 
         %img{"data-src" => "holder.js/140x140/text:Lorem ipsum/social", :src => "", :style => "width: 140px;height: 140px;"}/ 
       - if apr.event.app.check_user_failed == false && (apr.event.start_time.day == Time.zone.now.day) 
        %div 
         %span.btn.btn-default.btn-file 
          %span.fileupload-new Select image 
          =f.file_field "upload#{apr.id}" , accept: 'video/flv,video/avi,video/mov,video/mp4,video/mpg,video/wmv,video/3gp,video/asf,video/rm,video/swf', :data => {:max_file_size => 30.megabytes} 
        = transloadit_jquerify "showapr#{apr.id}", :wait => true, :modal=>true, :triggerUploadOnFileSelection=> true 
0

問題是你實際上沒有發佈正確的表單數據到API,以便它可以正確解析。

https://transloadit.com/docs/api-docs#status-codes

爲您提供:NO_PARAMS_FIELD沒有PARAMS字段指定。

是非常合情合理的,因爲你沒有通過PARAMS領域以及使用該API,當您使用transloadit的jQuery方法您使用

params: { 
"startdate":"2014-12-02", 
"endate":"2014-12-03", 
"auth":{ 
    "expires": "2014/12/27 16:53:14+00:00", 
    "key": "yourKeyValue" 
    } 
} 
&signature=yourUniqueSignature 

那麼,什麼是錯的參數是如何創建發送到API以使transloadit正常工作。