I am doing a file upload where I want to constrain the maximum size to 1 mb, and I can check this data after the upload has completed. Is there a way to check this before the upload actually starts?
on 2007-03-14 20:05
on 2007-03-14 20:13
dan kuwachi wrote: > I am doing a file upload where I want to constrain the maximum size to > 1 mb, and I can check this data after the upload has completed. Is > there a way to check this before the upload actually starts? I don't think you can do this. Rails will not even begin processing the action until the browser finishes sending the request. And the file upload is part of the request. I think you are at the mercy of HTTP here. But I could be completely wrong since I have heard of rails based file upload progress bars, so if anyone knows better feel free to shoot me down.
on 2007-03-15 01:45
If you're using mongrel, you can write a handler to get information about the incoming request before it's completely downloaded. You can then have your rails controllers connect to the handler via drb to get the content-length information the browser sends. Afaik, this is what mongrel's upload progress handler does: http://mongrel.rubyforge.org/docs/upload_progress.html It'll probably do what you need to do. If not, you can use it as inspiration for your own handler.