Rails, using Andrew Valum's uploader

Discussion in 'Ruby' started by Bigos, Feb 11, 2012.

  1. Bigos

    Bigos Guest

    Hi,

    I am trying to create multiple file upload using Andrew Valum's uploader
    http://valums.com/ajax-upload/ .

    When I try to upload example files I get following output:
    background1.jpg 22.2kB Successfully Uploaded!
    birdie.jpg 0.1MB Failed
    black.gif 1.5kB Failed

    Most of the time all files seem to be uploaded correctly despite having
    error messages.

    I can't understand what I am doing wrong here.



    Relevant code in application.html.erb

    <script>
    function createUploader(){
    var uploader = new qq.FileUploader({
    allowedExtensions: [],
    element: document.getElementById('file-uploader-demo1'),
    action: '/wedding_photos/multiupload',

    onComplete: function(id, fileName, responseJSON){
    if (responseJSON.success) {
    $$('.qq-upload-failed-text').first().update(' Successfully
    Uploaded!');
    }
    else
    {
    $$('.qq-upload-failed-text').first().update(' Hmm .. upload
    failed');
    }
    }
    });
    }
    // in your app create uploader as soon as the DOM is ready
    // don't wait for the window to load
    window.onload = createUploader;
    </script>




    And this is method definition in the relevant controller
    def multiupload
    logger.info "\n\n\n I'm in multiupload\n\n\n"

    @filename = params['qqfile']

    newf = File.open('/tmp/nextAttempt_' + @filename, "wb")
    str = request.body.read
    newf.write(str)
    newf.close

    render :text => '{success:true}'
    end

    --------the end----------the end---------
     
    Bigos, Feb 11, 2012
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.