Skip to main content
Inspiring
February 16, 2010
Answered

CFFile upload

  • February 16, 2010
  • 1 reply
  • 1165 views

Hello All,

After uploading a file with cffile to my a folder, I can't delete or use the file.

I'm getting this error:

error occurred - An error occurred - cannot delete remote file test.pdf.  The process cannot access the file because it is being used by another process.

Any ideas?

Thanks in advance.

Johnny

    This topic has been closed for replies.
    Correct answer A***

    You have opened your pdf file with <cfset pdf.openPdfFile(pdfFile)> before you got the page count. The file was not closed off thereafter. That is why you got the error message when you tried to delete.

    We just need to close the file within your function as below:

        <cffunction name="getPageCount">

            <cfargument name="pdfFile">

            <cfset var objName = "org.jpedal.PdfDecoder"/>

            <cfset var pdf = createObject("java", objName).init()/>      

            <cfset pdf.openPdfFile(pdfFile)>

            <cfset pages = pdf.getPageCount()>

            <cfset pdf.closePdfFile() />            <!--- Close file --->

            <cfset pdf = "">

            <cfreturn pages />

        </cffunction>

    1 reply

    Inspiring
    February 16, 2010

    This error normally comes up when a pdf file is open and one is trying to delete it at the same time.

    Is there any other application/user/reviewer reading or using the pdf file?

    jfb00Author
    Inspiring
    February 16, 2010

    Thanks for you help and reply.

    No, it' no other app usign the same file.

    Yes, we are uploading a pdf file like this:

    <cffile action="upload" destination="#expandpath('./attachments/')#"
                 filefield="pdf" nameconflict="makeunique" accept="application/pdf"/>

    Reading the pages with a  function:

        <cffunction name="getPageCount">
            <cfargument name="pdfFile">
            <cfset var objName = "org.jpedal.PdfDecoder"/>
            <cfset var pdf = createObject("java", objName).init()/>       
            <cfset pdf.openPdfFile(pdfFile)>
            <cfset pages = pdf.getPageCount()>
            <cfset pdf = "">
            <cfreturn pages />
        </cffunction>

    The file will show in our web site with an option delete button, if the user wants to delete it.

    Any other ideas?

    jfb00Author
    Inspiring
    February 16, 2010

    One more thing...

    If the user upload the same file again, we check before the upload and delete the file with this code:

    <cfif FileExists("#expandpath('./attachments/')##session.preview.pdf#")>
                <cffile action="delete" file="#expandpath('./attachments/')##session.preview.pdf#"/>
                <cfif StructKeyExists(form, 'remove_pdf')>
                    <cfset out.msg = 'File removed'/>
                    <cfset out.status = 1/>
                    <cfreturn out/>
                </cfif>
            </cfif>

    Thanks!