Is it possible to have 2 differnt file select fileds in transloadit form?

107 views Asked by At

So, I have a model (in a rails project) which has a logo and a cover image, I want to use one form for uploading both of them, is this possible to do with transloadit? I can't find an example anywhere...

1

There are 1 answers

0
Caner On

this is from my project. I use it 6 times. I hope it helps..

new.html.haml

- title t('.new_provider')
.spacer
.row
  .span12
    = render 'shared/flash_messages'
    %h1= yield :title
.row
  .span12
    = bootstrap_form_for @provider, validate: true, html: {edit: "false", id: "providerform", enctype:"multipart/form-data", class: 'form-horizontal' } do |f|
      = transloadit_jquerify :providerform, :wait => true, :modal=>false
      = f.error_messages
      = render 'form', f: f
      .form-actions
        = f.submit t('.create'), id: 'provider_submit', class: 'btn btn-large btn-primary', disable_with: t('helpers.disable_with')
= render 'providers/modal_phone_verification' 

_form.html.haml

  = f.text_area :business_description, :id =>"business_description", :rows => "4"
  .controls
    %p.help-block{style:"margin-bottom: 15px; margin-top: -20px;"}
      %small
        = t('business_description_placeholder') 
  .control-group
    = label_tag :business_photos, t('.business_photos'), class: 'control-label'
    .controls
      = render partial: 'file_upload', :locals => {f: f}
      %span#file-error.help-inline{style: "display:none;color: #b44337"}=t('.file_presence_error')  
  .control-group
    .controls
      %p.help-block{style:"margin-bottom: 0px; margin-top: -20px;"} 
        %small
          = t('image_info')  

_file_uplaod.html.haml

= transloadit :image_resize
-6.times do |index|
  .fileupload.fileupload-new.pull-left{style: "padding-right: 5px;", "data-provides" => "fileupload" }
    .fileupload-new.thumbnail{:style => "width: 130px; height: 130px;"} 
      -if @provider.provider_images.present?
        - if @provider.provider_images["provider_image#{index+1}"].present?
          %img{:id=>"providerimage1", :src => @provider.provider_images["provider_image#{index+1}"][0]}/
    .fileupload-preview.fileupload-exists.thumbnail{:style => "width: 130px; height: 130px;"}
    %div
      %span.btn.btn-file
        %span.fileupload-new{:id => "selectbutton"}
          -if index == 0
            =t('select_profile_image')  
          -else
            =t('select_image')              
        %span.fileupload-exists
          -if index == 0
            =t('select_profile_image')  
          -else
            =t('select_image')      
        =file_field_tag "provider_image#{index+1}", accept: 'image/png,image/bmp,image/jpeg,image/tif,image/jpg', :onchange =>"validateImageFiles(this);", :data => {:max_file_size => 5.megabytes}