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

HELP!! Urgent!!

New Here ,
May 19, 2010 May 19, 2010

Hello, everybody!

I know absolutely nothing about ColdFusion ... However, we are working on a project with a vendor who IS using ColdFusion.

Simply put (yeah, right):

We have a form, that requests a zip file. The coldfusion code, in the background, is using java.util.zip and such, to handle the PDF file.

The zip files contain PDF files (two zip files). At the moment, approximately 5 pdf files, each. 5 of the pdf files average 1.2MB (each) when fully extracted, the other 5 roughly 180K (each).

However .... and here's the weird thing:

When the files are extracted, and the User Interface is used to open the PDF file, it's telling us the file is corrupt.

So, what I did was, pulled the file out of the zip file, THEN, downloaded the so called corrupt file, and did a compare ... and noticed that about 50 lines or so, were missing from the corrupted file. I simply copied the binary stuff that was missing, pasted into the corrupted file, saved, closed, and voiala.... I was able to open it.

This is telling me that the java.util.zip process, or whatever, is not writing all of the data for some of the pdf files.... leading me to believe, a crc error somewhere ....

Here's the odd thing:

The way we are using these pdf files:  The user logs in, and sees two separate links to two separate pdf files ... I click on the button, the PDF file is supposed to open up... Let's call them Test A and Test B. Our user imported the first zip files which included all of the Test A files ... then imported the other zip file that included all of the Test B files... But, the strange thing is, when we were testing it, Person A was able to open BOTH test files, however, myself, and another, could only open the Test B files, NOT the Test A files. Very strange....

Below, is the code that is being used in coldfusion, using the java.util.zip library or whatever you call it... I'm trying to help, by researching this stuff too...

==========================================================

<cfscript>

        /* Create Objects */
        ioFile      = CreateObject("java","java.io.File");
        ioInput     = CreateObject("java","java.io.FileInputStream");
        ioOutput    = CreateObject("java","java.io.FileOutputStream");
        ioBufOutput = CreateObject("java","java.io.BufferedOutputStream");
        zipFile     = CreateObject("java","java.util.zip.ZipFile");
        zipEntry    = CreateObject("java","java.util.zip.ZipEntry");
        zipInput    = CreateObject("java","java.util.zip.ZipInputStream");
        zipOutput   = CreateObject("java","java.util.zip.ZipOutputStream");
        gzInput     = CreateObject("java","java.util.zip.GZIPInputStream");
        gzOutput    = CreateObject("java","java.util.zip.GZIPOutputStream");
        objDate     = CreateObject("java","java.util.Date");

        /* Set Variables */
        this.os = Server.OS.Name;

        if(FindNoCase("Windows", this.os)) this.slash = "\";
        else                               this.slash = "/";

    </cfscript>


    <cffunction name="Extract" access="public" output="no" returntype="boolean" hint="Extracts a specified Zip file into a specified directory.">

        <!--- Function Arguments --->
        <cfargument name="zipFilePath"    required="yes" type="string"                              hint="Pathname of the Zip file to extract.">
        <cfargument name="extractPath"    required="no"  type="string"  default="#ExpandPath(".")#" hint="Pathname to extract the Zip file to.">
        <cfargument name="extractFiles"   required="no"  type="string"                              hint="| (Chr(124)) delimited list of files to extract.">
        <cfargument name="useFolderNames" required="no"  type="boolean" default="yes"               hint="Create folders using the pathinfo stored in the Zip file.">
        <cfargument name="overwriteFiles" required="no"  type="boolean" default="no"                hint="Overwrite existing files.">

        <cfscript>

            /* Default variables */
            var l = 0;
            var entries  = "";
            var entry    = "";
            var name     = "";
            var path     = "";
            var filePath = "";
            var buffer   = RepeatString(" ",1024).getBytes();

            /* Convert to the right path format */
            arguments.zipFilePath = PathFormat(arguments.zipFilePath);
            arguments.extractPath = PathFormat(arguments.extractPath);

            /* Check if the 'extractPath' string is closed */
            lastChr = Right(arguments.extractPath, 1);

            /* Set an slash at the end of string */
            if(lastChr NEQ this.slash)
                arguments.extractPath = arguments.extractPath & this.slash;

            try
            {
                /* Open Zip file */
                zipFile.init(arguments.zipFilePath);

                /* Zip file entries */
                entries = zipFile.entries();

                /* Loop over Zip file entries */
                while(entries.hasMoreElements())
                {
                    entry = entries.nextElement();

                    if(NOT entry.isDirectory())
                    {
                        name = entry.getName();

                        /* Create directory only if 'useFolderNames' is 'yes' */
                        if(arguments.useFolderNames EQ "yes")
                        {
                            lenPath = Len(name) - Len(GetFileFromPath(name));

                            if(lenPath) path = extractPath & Left(name, lenPath);
                            else        path = extractPath;

                            if(NOT DirectoryExists(path))
                            {
                                ioFile.init(path);
                                ioFile.mkdirs();
                            }
                        }

                        /* Set file path */
                        if(arguments.useFolderNames EQ "yes") filePath = arguments.extractPath & name;
                        else                                  filePath = arguments.extractPath & GetFileFromPath(name);

                        /* Extract files. Files would be extract when following conditions are fulfilled:
                           If the 'extractFiles' list is not defined,
                           or the 'extractFiles' list is defined and the entry filename is found in the list,
                           or the file already exists and 'overwriteFiles' is 'yes'. */
                        if((NOT IsDefined("arguments.extractFiles")
                            OR (IsDefined("arguments.extractFiles") AND ListFindNoCase(arguments.extractFiles, GetFileFromPath(name), "|")))
                           AND (NOT FileExists(filePath) OR (FileExists(filePath) AND arguments.overwriteFiles EQ "yes")))
                        {
                            // Skip if entry contains special characters
                            try
                            {
                                ioOutput.init(filePath);
                                ioBufOutput.init(ioOutput);

                                inStream = zipFile.getInputStream(entry);
                                l        = inStream.read(buffer);

                                while(l GTE 0)
                                {
                                    ioBufOutput.write(buffer, 0, l);
                                    l = inStream.read(buffer);
                                }

                                inStream.close();
                                ioBufOutput.close();
                                ioOutput.close();
                            }

                            catch(Any Expr)
                            { skip = "yes"; }
                        }
                    }
                }

                /* Close the Zip file */
                zipFile.close();

                /* Return true */
                return true;
            }

            catch(Any expr)
            {
            dumpvar(expr);
                /* Close the Zip file */
                zipFile.close();

                /* Return false */
                return false;
            }

        </cfscript>

    </cffunction>

==========================================================

553
Translate
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 ,
May 19, 2010 May 19, 2010

What version of ColdFusion?

The current versions of ColdFusion, version 8 and version 9, come with built in support for PDF generation and minipulation and ZIP compression.  One should not have to dip into the underlining Java functionality.

Have you investigated if this could be a delivery problem?  Something somehow is not making it to the destination.  That would be highly unusually, but you seem to be describing a rather unusual situation.

Have you tried deliviering content without the compression?  Just to see if you can isolate the probelm to the compression and not something about the PDF files themselves?

Translate
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 ,
May 19, 2010 May 19, 2010
LATEST

Have you tried deliviering content without the

compression?  Just to see if you can isolate the probelm to

the compression and not something about the PDF files

themselves?

All good points. Especially the last one.

If you verify it is not an issue with the pdf files, one change you might make is to explicitly flush() the output streams before closing them. Granted it is supposed to happen automatically when close() is called. But on the off chance it is not happening, an explicit call would not hurt.

....

ioBufOutput.flush();

ioOutput.flush();

ioBufOutput.close();

ioOutput.close();

Translate
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