Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to find uploaded data size from content-length

Reply
Thread Tools

How to find uploaded data size from content-length

 
 
Asterbing
Guest
Posts: n/a
 
      04-19-2006
Considering a multipart/form-data form, is there a formula to calculate
the size of an uploaded file from within $ENV{'CONTENT_LENGTH'} which
represent the size of the entire data in STDIN (including all name/value
pairs, boundary between parts, content-disposition & type lines, some
blank lines) ?
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-19-2006
Asterbing <> wrote:
> Considering a multipart/form-data form, is there a formula to calculate
> the size of an uploaded file from within $ENV{'CONTENT_LENGTH'} which
> represent the size of the entire data in STDIN (including all name/value
> pairs, boundary between parts, content-disposition & type lines, some
> blank lines) ?


No.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      04-19-2006
Asterbing <> wrote:

> Considering a multipart/form-data form, is there a formula to calculate
> the size of an uploaded file from within $ENV{'CONTENT_LENGTH'} which
> represent the size of the entire data in STDIN (including all name/value
> pairs, boundary between parts, content-disposition & type lines, some
> blank lines) ?


Why not -s filename assuming you store it in a file system?

--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
Asterbing
Guest
Posts: n/a
 
      04-19-2006
In article <Xns97AA6D15AEC7Fcastleamber@130.133.1.4>,
says...
> Why not -s filename assuming you store it in a file system?
>


Because I would like to avoid too big files
 
Reply With Quote
 
Asterbing
Guest
Posts: n/a
 
      04-19-2006
In article <20060419114637.129$>,
says...
>
> No.
>


Why ?
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      04-19-2006
Asterbing <> wrote:

> In article <Xns97AA6D15AEC7Fcastleamber@130.133.1.4>,
> says...
>> Why not -s filename assuming you store it in a file system?

>
> Because I would like to avoid too big files


Ok, so your question actually is: how do I avoid the uploading of big
files:

$CGI:OST_MAX

If set to a non-negative integer, this variable puts a ceiling on the
size of POSTings, in bytes. If CGI.pm detects a POST that is greater than
the ceiling, it will immediately exit with an error message. This value
will affect both ordinary POSTs and multipart POSTs, meaning that it
limits the maximum size of file uploads as well. You should set this to a
reasonably high value, such as 1 megabyte.


(documentation of CGI.pm, Avoiding Denial of Service Attacks)

--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-19-2006
John Bokma <> wrote:
> Asterbing <> wrote:
>
> > In article <Xns97AA6D15AEC7Fcastleamber@130.133.1.4>,
> > says...
> >> Why not -s filename assuming you store it in a file system?

> >
> > Because I would like to avoid too big files

>
> Ok, so your question actually is: how do I avoid the uploading of big
> files:
>
> $CGI:OST_MAX
>
> If set to a non-negative integer, this variable puts a ceiling on the
> size of POSTings, in bytes. If CGI.pm detects a POST that is greater than
> the ceiling, it will immediately exit with an error message.


That should probaby be changed. It does not immediately exit with
an error message. It first reads (and discards) the entire contents
of the POST, which apparently the OP doesn't want to happen althought it
is kind of hard to figure out exactly what he wants. Also, it doesn't
exit at all. It causes param to return an empty param list, and it causes
cgi_error to return an error message--no exiting involved.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      04-19-2006
Asterbing <> wrote:
> In article <20060419114637.129$>,
> says...
> >
> > No.
> >

>
> Why ?


Why isn't the moon made out of green cheese?

You pretty much covered why in the post. You can't figure out how the
sizes of the different parts of the post (which sum up to CONTENT_LENGTH)
are distributed until you read all but one of them. Since you can't
gaurantee that the part which contains the file upload is the last part,
you can't figure out how big that part is until you have read it.

I have no idea why you think you need to do this.....

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Asterbing
Guest
Posts: n/a
 
      04-19-2006
In article <20060419144430.442$>,
says...
> I have no idea why you think you need to do this.....
>


Because when CONTENT_LENGTH has been informed by server itself after
receiving of entire POST, I can effectively read STDIN, extract uploaded
data and do the substraction.

But, when CONTENT_LENGTH comes from original request, how to proceed ?

Say, I wish to avoid any upload (I mean write on server, since data may
already be in STDIN) above 1MB, how to proceed ?
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      04-19-2006
wrote:

> John Bokma <> wrote:
>> Asterbing <> wrote:
>>
>> > In article <Xns97AA6D15AEC7Fcastleamber@130.133.1.4>,
>> > says...
>> >> Why not -s filename assuming you store it in a file system?
>> >
>> > Because I would like to avoid too big files

>>
>> Ok, so your question actually is: how do I avoid the uploading of big
>> files:
>>
>> $CGI:OST_MAX
>>
>> If set to a non-negative integer, this variable puts a ceiling on
>> the
>> size of POSTings, in bytes. If CGI.pm detects a POST that is greater
>> than the ceiling, it will immediately exit with an error message.

>
> That should probaby be changed. It does not immediately exit with
> an error message. It first reads (and discards) the entire contents
> of the POST, which apparently the OP doesn't want to happen althought
> it is kind of hard to figure out exactly what he wants. Also, it
> doesn't exit at all. It causes param to return an empty param list,
> and it causes cgi_error to return an error message--no exiting
> involved.


You mean it reads until it detects that the max size has been reached?
Yes, that's what I expect, since one can keep streaming bytes, and only
when the max has been reached the script knows it was too much.

The second part: if the documentation is wrong, it must be fixed. Did you
submit this?

--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
check uploaded file's file size? h3m4n Python 2 07-08-2006 08:56 PM
Uploaded File, passing to EJB, memory size RobM Java 0 10-05-2005 12:17 AM
Limiting Uploaded File Size Johnson ASP .Net 4 02-19-2005 01:51 AM
Virus-Scanning uploaded files uploaded? Matt G ASP .Net 1 08-22-2003 05:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57