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

Checking File Size with Java

Guest
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

I am trying to upload a zip file using cfzip in an application I am working on. I am using Java to get the files size before the file is uploaded however the results of the "scan" and the size of the fiel are completely different and I was hoping someone could point me to what is wrong.

Here is the java code

    <!--- check the size of the zip file --->
    <cfif len(form.zipGallery)>
        <cfset f = createObject("java","java.io.File").init(form.ZipGallery)>
        <cfif f.length() gt (25 * 2048)>
            <cfset valError = listAppend(valError,"That file is too large. Please make you zip file less than 25MB" & "-" & #f.length()#)>
        </cfif>
    </cfif>

The file is  23.6 MB and it returns a value of 24804509.

What am I missing?

Thanks in advance.

TOPICS
Advanced techniques

Views

1.5K

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

correct answers 1 Correct answer

Enthusiast , Apr 20, 2009 Apr 20, 2009

the actual file size is 23.65542316436767578125 mb or something like that.

the length() method returns bytes. divide by (1024 * 1024) to get mb.

Votes

Translate

Translate
Enthusiast ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

the actual file size is 23.65542316436767578125 mb or something like that.

the length() method returns bytes. divide by (1024 * 1024) to get mb.

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
Valorous Hero ,
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

RandomActsDesign wrote: ...

I am using Java to get the files size before the file is uploaded however the results of the "scan" and the size of the fiel are completely

Well .. technically the file was already uploaded.  It is sitting in a temp directory on the server.  cffile action=upload just moves the temp file to its final destiation and restores the file extension.

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
Apr 20, 2009 Apr 20, 2009

Copy link to clipboard

Copied

Now I'm just a tad confused. That little bit of code is on the validation page. The upload doesn't even happen until it reaches the processing page so how could it already be on the server.

Here is how I make my forms. I find it easier to keep each portion seperate for future changes. The form validation page is where the file check is. If it finds any errors it brings the input page back up. If not the processing page is run.

<cfswitch expression="step">

    <cfcase value="process">

          <cfinclude template="formValidation.cfm">

    </cfcase>

     <cfdefaultcase>

          <cfinclude template="formInput.cfm">

     <cfdefaultcase>

</cfswitch>

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
Valorous Hero ,
Apr 21, 2009 Apr 21, 2009

Copy link to clipboard

Copied

RandomActsDesign wrote:

Now I'm just a tad confused. That little bit of code is on the validation page. The upload doesn't even happen until it reaches the processing page so how could it already be on the server.

When your typical form is submitted to the server, everything, including files, are uploaded with it. Any files submitted are placed in a temp directory. (You can see the path by cfdump'ing the FORM scope). When you run cffile action=upload, the file(s) are simply moved from the temp directory to another location and renamed.

If you think about it, CF runs on your server. It has no way to access files on a user's machine.  Can you imagine if it did? That would mean any web site could access files on your computer at will, which would be a big security hole.  So there is no way CF (or your server side java)  could know the file size unless that file is already uploaded to your server.

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
Community Expert ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

RandomActsDesign wrote:

Checking File Size with Java

Why the extra expense of creating a Java object when you can just obtain the file size from cffile.filesize?

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
Valorous Hero ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

LATEST

BKBK wrote:

RandomActsDesign wrote:

Checking File Size with Java

Why the extra expense of creating a Java object when you can just obtain the file size from cffile.filesize?

Yes, I see I left that out of the explanation.  I suspect they were using a java object because they did not realize the file was already on the server, so you might as well just do a cffile upload.

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 ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

I've not tried it, but this looks like it might work.  http://www.webdeveloper.com/forum/archive/index.php/t-53380.html

vbscript does run on the client I presume.

Note the caveat about IE.  If this is a public site, you'll have to test it on firefox as well, plus on a mac.

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