• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to check file size on upload? In case file is massive...

New Here ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

Hi, I have an upload file button on my page, is there a way to check a file size before allowing user to upload file. Right now, if a user uploads a huge file (5 gigs), it would crash is there a file to somehow stop them? I've researched forums and all say that you have to first upload the file and then check the file size with cffile, but is there another way?

Thanks so much,
c
TOPICS
Advanced techniques

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

you can try using cgi.content_length which will report total size of
content being processed by the page (file size + page size + other
stuff) in bytes... but i can't remember if it has to upload the file to
the cf temp dir first or not...


--
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

CGI.CONTENT_LENGTH is used after the file is uploaded.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

When this is an issue for me, I use SmartASPUpload. Unfortunately, the vendor has discontinued it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

To do this before the upload happens - you are looking at client side
solutions. JavaScript, Active X and Flash are possible client side
technologies that will help you with this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

Hi all, thank you all for you comments. Currently if the file is too big, I get a server error page and the file is never uploaded so I never even get a chance to check on file properties...
Does anyone have a client-side solution to this? I found one that works only in IE that worries me, does anyone have a sample for all browsers (ie, firefox, netscape...) ?

Thanks so much,
C

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

The last time this topic came up on these forums, someone pointed out a
Flash widget that would give you control like this and more to uploading
files. I have never tried it, but it looked kind of interesting when I
glanced at it.

Unfortunately I don't remember anything about it anymore. I would hope
searching the archives and|or Google turn up something. Good Luck.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 26, 2007 Feb 26, 2007

Copy link to clipboard

Copied

Some uploading tools available here:

http://www.cftagstore.com

Unfortunately, because of the nature of HTTP protocol, the safest solution is to limit the size of upload on the server side with "the crash page" by setting limit on HTTP request as a Web-server property or a CF property. There is also CFX tag similar to ASPUpload.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2007 Mar 01, 2007

Copy link to clipboard

Copied

I think that previous conversation was started by me. We eventually went with a Java FTP applet solution by UltimateFTP. Because it's FTP you don't have to worry about http uploads or overloading CF Server stack. Also, that applet allows you to limit the file size that is uploaded. Unfortunately it is very expensive... around $1200 or so. There are other FTP applet solutions out there, like RAD Uploader (which also has a neat http solution that can go around CF) but there were other constraints in my project.

Hopefully CF will take care of this in v.8 since files are getting larger and larger. I envision a nice cfupload form element that creates a nice Java browse applet with the appropriate bells and whistles (including xfer resume) and is handled by a single thread for ALL upload requests on the server. That would be sweet.

Mik

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2007 Mar 01, 2007

Copy link to clipboard

Copied

Specifically, this is a feature request I just sent in:

CFUPLOAD

Launches a java applet on client side to allow multiple file uploads, with certain restrictions (ie; max number of files, total size, etc) and submit either as http to a single thread handler for WHOLE SERVER (so many simultaneous very large uploads, ie 1gb each, don't take down the server handles) or ftp.

Why is this important? File sizes are getting larger and larger and there's more and more video on the Internet. We need an easy way of dealing with this. Solve it for us.

Also, I hear tell that there's going to be image manipulation tags in v8. Excellent. Can you also put in some simple video manipulation tags, such as discovering the x y size of the video and grabbing a thumbnail frame?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2007 Mar 01, 2007

Copy link to clipboard

Copied

And to continue my vamp... very large file downloads don't work either. Either IIS or IE has a 2gb limit on downloads. Yeah, sure, you say "WTF, is he kidding?" well, I remember not too long ago dialing into a BBS with a 2400 baud modem and thinking a 5MB file was ludicrous. 2gb over Verizon's new FIOS will take very little time. We need a solution that doesn't involve FTP, unless CF can solve it with a Java FTP solution ( CFDOWNLOAD? )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 04, 2007 Mar 04, 2007

Copy link to clipboard

Copied

Maybe this code helps.
Here is the code:
<cfscript>
function FileSize(filename){
var theFile = createObject("java", "java.io.File");
theFile.init(JavaCast("string", filename));
return theFile.length();
}
</cfscript>
<cfif FileSize(form.fileFieldName) LT 2000000> <-- file up to 2 MB--->

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 04, 2007 Mar 04, 2007

Copy link to clipboard

Copied

Maybe this code helps.

<cfscript>
function FileSize(filename){
var theFile = createObject("java", "java.io.File");
theFile.init(JavaCast("string", filename));
return theFile.length();
}
</cfscript>
<cfif FileSize(form.fileFieldName) LT 2000000> <-- file up to 2 MB--->

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2007 Mar 05, 2007

Copy link to clipboard

Copied

Thank you for your comments, billdimit and michaelmuller, I will try the code out on my end.

Thanks again,
C

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2007 Mar 06, 2007

Copy link to clipboard

Copied

LATEST
Hi billdimit, thanks for your code, I tried it out and it finds the files size but if the file is huge (1 gig) then I get "The page cannot be displayed", I think this may be because server cannot handle such a large file?

Thanks,
C

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation