Skip to main content
April 16, 2008
Answered

CFImage bug?

  • April 16, 2008
  • 2 replies
  • 2785 views
I'm having a problem with CFImage where it seems to be locking the image file it is using, making it unable to be deleted (even in windows file explorer).

Here is the scenario:
I upload an image file using cffile action=upload

I read the file in using cfimage

I resize the file (using imageResize()) and write it to disk using CFImage action="write" with a new file name.

I then try to delete the original uploaded file, and get an error:
ColdFusion could not delete the file d:\inetpub\wwwroot\site\cfml\images\listingimages\1998\000_0202.jpg for an unknown reason.

The reason appears to be that ColdFusion had locked the file. It only seems to happen with files over 300K in size.

I've tried everything I can think of to delete the file. Some have stayed locked and unable to delete until I restart the CF services.

I'm running CF8.0.1 on Win2003 server. Thanks for any help you can give.
This topic has been closed for replies.
Correct answer
I submitted the bug report. Now I just realized that I should have mentioned this thread in that report.

If anyone else is going to submit one, include a link to this thread in the report as well.

Thanks,

Try Patch for CFImage and Image functions in ColdFusion 8.0.1 (kb403411)

2 replies

Known Participant
April 20, 2008
We have this same issue. It seems to happen with every image now.

I believe it has something to do with a recent CF update that one of our customer's hosting providers has applied, however they do not know which it is.

I was thinking of a fix involving uploading the new file to the CFTemporary directory. However I was wondering if and how often the CFTemp directory is purged automatically.
April 21, 2008
We came up with a workaround since the issue seems to be a bug. We are now uploading to a directory, reading the file and resizing, then saving it to a different directory (leaving us with 2 files). This way the original file can stay locked because we never write to it. To get rid of the original files in that directory, we run the attached code nightly as a scheduled task to purge any images from that upload directory that haven't been accessed in the last 30 minutes. The files seem to unlock after a period of time, so deleting them hasn't been a problem. So far this workaround has done the job.

Please post back if you found a better solution or a fix.
Known Participant
April 21, 2008
That's pretty much what we were going to do, except with using the CF Temp directory to try and handle the auto delete. I don't see any other way to work around this.
Participant
April 17, 2008
We have noticed the same issue in the same type environment (CF8.0.1 on Win2003 server).

For us, it seems to lock the source image no matter the size of the jpg. After the file is uploaded, we try to resize it and then write the image back out to the same filename (with overwrite="true"). This causes an error. Resizing to a different filename works.

For us it seems any JPG image that is used as the source in a cfimage resize will be left locked.

We have tried using cfimage with source and destination set (as the same JPG file name with OS path) and Overwrite set to true (RESULT: Errors out with "Ensure that the destination directory exists and that Coldfusion has permission to write to the given path or file. cause : java.io.FileNotFoundException").

We have tried resizing the image into memory then tried to cffile delete the source file... wanting to write the image back to the drive from memory (RESULT: errors out saying the file cannot be deleted)

What we have done for now is to rename the file to a XXXXX_TEMP.JPG temp file and resize it to the needed destination. Works perfectly but leaves behind _TEMP.JPG files that cannot be deleted due to a file lock.

As Administrator on the server we cannot delete or rename the source file for about 30-45 minutes after the resize is completed (or we restart the ColdFusion service)

Any work around or fixes to this issue would be greatly appreciated.

TIA