Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari 5(.1.1) doesn't support window.fileReader #37

Closed
JeanMertz opened this issue Oct 17, 2011 · 5 comments
Closed

Safari 5(.1.1) doesn't support window.fileReader #37

JeanMertz opened this issue Oct 17, 2011 · 5 comments

Comments

@JeanMertz
Copy link

While working with the upload feature I noticed it not working (and not giving any errors) in Safari 5.1.1. After digging around I noticed @supported() returned false because window.fileReader returns false.

After Googling I found this url which explains the issue: http://castlesblog.com/2010/july/13/html5-drag-drop-upload

I haven't implemented a fix or workaround yet, but I just wanted to let you know in advance.

also see: http://caniuse.com/filereader

@jejacks0n
Copy link
Owner

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?

@jejacks0n
Copy link
Owner

@JeanMertz
Copy link
Author

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.

@shadowhand
Copy link
Contributor

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

@mixonic
Copy link
Contributor

mixonic commented Mar 15, 2012

Please help review this pull request: #184 Thanks!

DougPuchalski pushed a commit to DougPuchalski/mercury that referenced this issue Mar 23, 2012
Safari uploads, closes jejacks0n#37. Please help review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants