Giter Site home page Giter Site logo

Comments (5)

tors avatar tors commented on June 17, 2024 1

@felixbuenemann Reasonable points. Let's go ahead and remove the middleware.

from jquery-fileupload-rails.

felixbuenemann avatar felixbuenemann commented on June 17, 2024

@tors @opti What do you think?

from jquery-fileupload-rails.

opti avatar opti commented on June 17, 2024

@felixbuenemann I have no objections on that. However, I have never faced to the necessity of using this middleware for all the time I have been using this gem.

from jquery-fileupload-rails.

jhubert avatar jhubert commented on June 17, 2024

@felixbuenemann I've been struggling with iframe transport and rails and this middleware helped. Are you able to give some examples as to how you handle this in the controller without the middleware?

from jquery-fileupload-rails.

felixbuenemann avatar felixbuenemann commented on June 17, 2024

@jhubert I haven't looked at this for a long time. It seems that at the very least the client would have to add a header like 'X-Requested-With: IFrame' so the controller could detect iframe requests and then alter the Content-Type to text/html so eg IE wouldn't show a download prompt. It can then return the response wrapped in a textarea which has data-type, data-status and data-statusText attributes with the relevant data. This is documented in the jquery-iframe-transport.js docs.

I do remember discussing this issue upstream, where I did a PR to include the 'X-Requested-With: IFrame' header in the ajax request, but it was rejected because supposedly there's another way to detect this. If your controller only accepts requests from jquery file uploader, then for non-iframe request request.xhr? will be truthy and for iframe requests if will be falsy. This technique does not help you if you get normal form uploads without js to the same controller action, because they will look the same as the iframe upload.

You can then do something like this:

respond_to do |format|
  format.html do
    if request.xhr?
      # render normal response
    else
      # render response wrapped in textarea for iframe transport
    end
  end
end

from jquery-fileupload-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.