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

CFFile upload

Advisor ,
Feb 16, 2010 Feb 16, 2010

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

993
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

correct answers 1 Correct answer

Participant , Feb 16, 2010 Feb 16, 2010

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)>

  

...
Translate
Participant ,
Feb 16, 2010 Feb 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?

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
Advisor ,
Feb 16, 2010 Feb 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?

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
Advisor ,
Feb 16, 2010 Feb 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!

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
Participant ,
Feb 16, 2010 Feb 16, 2010

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>

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
Advisor ,
Feb 16, 2010 Feb 16, 2010
LATEST

You got it Man,

Thanks for you help!

Don't know how is was working fine with CF7 for so long

Regards

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