tors / jquery-fileupload-rails

jQuery File Upload integrated for Rails
669 stars 254 forks source link

preview image/video not working #79

Closed piya23300 closed 9 years ago

piya23300 commented 9 years ago

I use this gem at master branch.

I have a problem. preview not working. I found that file object doesn't has preview method.

when always callback work and than I print log of file object

var file = data.files[0]
log.console(file)

at demo https://blueimp.github.io/jQuery-File-Upload/basic-plus.html file has preview method file demo

but ... at my project file doesn't has preview method file my project

Cloud you help me please? Below is my code.


at application.js

//= require jquery-fileupload/basic-plus
//= require video_uploader

at video_uploader.coffee

$( document ).ready ->
  btnUploader = $('.fileupload')
  progressBar = $('.fileupload-progress')

  btnUploader.fileupload
    disableImageResize: false,
    previewMaxWidth: 100,
    previewMaxHeight: 100,
    previewCrop: true,

    add: (e, data)->
      console.log 'start'
      data.context = $('<div />').appendTo('.videopreview')
      file = data.files[0]
      console.log file.name
      console.log file.preview
      console.log data.context
      node = $('<p/>').append($('<span/>').text(file.name))
      node.appendTo(data.context)
      data.submit()

    submit: (e, data)->
      progressBar.text('Uploading : 0%')
      true

    # send: (e, data)->

    progress: (e, data)->
      progress = parseInt(data.loaded / data.total * 100, 10)
      if progress < 100
        progressBar.text('Uploading : '+progress+'%')
      else
        progressBar.text('Processing Video')

    done: (e, data)->
      progressBar.text('Uploading Finished')

    fail: (e, data)->
      progressBar.text('Uploading Failed!')

    always: (e, data)->
      console.log 'processalways'
      file = data.files[0]
      console.log file
      console.log data.context
      node = $(data.context.children()[0])
      node
        .prepend('<br>')
        .prepend(file.preview)

at _form.html.erb

<div class="form-group">
   <%= f.input :file, as: :file, input_html: { class: 'fileupload' } %>
</div>
<div class="fileupload-progress></div>
<div class="col-xs-offset-3 col-xs-4 videopreview"></div>
felixbuenemann commented 9 years ago

You are using the wrong callback, use btnUploader.fileupload().on('fileuploadprocessalways', (e, data)-> …)and it'll work. I think you'll have to use the on('fileuploadeventname') syntax, because the event is triggered asynchronously by the process plugin.