Forum: Ruby on Rails is it possible to determine the file size before an actual u

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B3704e5f5327b11254091a936d08eb99?d=identicon&s=25 dan kuwachi (Guest)
on 2007-03-14 20:05
(Received via mailing list)
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?
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (squeegy)
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.
8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-03-15 01:45
(Received via mailing list)
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.
This topic is locked and can not be replied to.