Copy link to clipboard
Copied
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
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)>
...
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
You got it Man,
Thanks for you help!
Don't know how is was working fine with CF7 for so long
Regards