vendredi 28 octobre 2016

How to configure Fine Uploader to make Rails-compatible requests?

Using Fine Uploader with Rails 3.2, I don't know how to configure Fine Uploader to make upload requests that the Rails backend can authorise.

The Fine Uploader front-end element works fine and targets my resource (uploads), but because the uploads#create endpoint is guarded by authorisation (user must be logged in) the request has to contain valid session information to be let through. And it doesn't, so the upload of course fails.

How do I make Fine Uploader make requests that contain the necessary information for Rails to accept this as part of the user's session?

For what it's worth I initialise the uploader like this:

app/views/uploads/index.html.haml

[ ...template... ]

:javascript
    var uploader = new qq.FineUploader({
        debug:true,
        element: document.getElementById("uploader"),
        request: {
            endpoint: '/uploads',
        }
    })

It makes a POST /upload request which is routed to upload#create, but fails authorisation because of checks in the controller like this:

def session_exists?
    return true if !session[:user_id].blank?`

Any insights appreciated.

Aucun commentaire:

Enregistrer un commentaire