Coder Social home page Coder Social logo

Comments (5)

jejacks0n avatar jejacks0n commented on July 21, 2024

Yeah.. thanks for doing this research. I had tracked most of this down at one point, and was aware that the file uploading wasn't working in safari, although I think I may have since forgotten that. Bummer.

There's a bit of a long story behind this, and now that I'm thinking about it, it's beginning to flood back. The reason for a lot of the extra file upload code is to avoid doing really hacky stuff in rails / rack.

I know you can easily send the whole file to the server, that's actually really really easy, and was part of my first pass at the file uploading javascript.. The not so easy part comes into play with how the server knows that it should do something with it. Right? So, for rails to know that it's something it cares about, the request must first make it through rack, with params set that rails can route, and then the controller takes over and uses those params to save a model / process the file.

While I was writing and playing around with the uploading code I was using a simple php script that would accept a file, and since php is pretty simple with things like that it was all fine.. The problem came up with when I switched it over to rails and tried to upload a file. It never made it through rack to the rails application, for obvious reasons -- there were no params to get the file information from. So, turns out that rails, via rack just disregards that file upload because it's totally not known to the rails server.. Nor is there any information about what that file is a property of (so saving a model and having paperclip do it's thing isn't possible).. In other terms, there no way to make that into a valid form submission without doing something nasty within rack. Right?

So enter awesomely annoying multi-part form building in javascript (took me about 8 hours to figure out and get working btw). You should poke around in that code and look at how the multi-part form is built.. Understanding that it's all there so Rails can process the file at a given route.

Basically, we could try to patch rack to handle that better (seems unlikely that would ever make it in though), or we work around it in the browsers where we can. Not sure of the best solution here, but if you can make rack/rails accept the file upload and route it properly with the right params I will adjust the javascript. ;-P

But seriously, I did spend about an hour playing around with a little rack app / metal layer that would try and grab that file, but gave up after a while because it felt dirty to me.. but maybe in hindsight not as dirty as the multi-part form stuff? I vaguely remember having to set several X- style headers to give rack the information it would need to pass it along to rails, and it just didn't feel right.

I'm going to put that in as a known issue for safari, and leave this issue open, but do you have any additional thoughts?

from mercury.

jejacks0n avatar jejacks0n commented on July 21, 2024

added the issue to https://github.com/jejacks0n/mercury/wiki/Known-Issues

from mercury.

JeanMertz avatar JeanMertz commented on July 21, 2024

My first thought would be: custom middleware. But I am writing this while I just woke up so I'll give it some more thought at work.

from mercury.

shadowhand avatar shadowhand commented on July 21, 2024

I don't have anything to add, just want future notifications on this. :)

from mercury.

mixonic avatar mixonic commented on July 21, 2024

Please help review this pull request: #184 Thanks!

from mercury.

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.