Question

This code used to work fine with ColdFusion 9:

<cfif form.btnSaveImage EQ "Upload">
    <cftry>
        <cffile accept="image/*" action="upload" destination="C:\T" filefield="vcImageFile" nameconflict="overwrite">
        <cfcatch type="Any">
            <cfdump var="#cfcatch#" label="cfcatch">
        </cfcatch>
    </cftry>
</cfif>

<form action="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>" method="post" name="frmImagesAdd" id="frmImagesAdd" enctype="multipart/form-data">
    <label for="vcImageFile">Image File*:</label><br>
    <input type="file" name="vcImageFile" id="vcImageFile" size="40" maxlength="255" message="Image file is required to upload."><br>
    <input type="hidden" name="btnSubmit" value="Add Image">
    <input name="btnSaveImage" type="submit" value="Upload">
</form>

The issue is the accept="image/*" attribute of the cffile tag. In ColdFusion 9, this wildcard used to accept any file with a MIME type that started with "image/". In ColdFusion 10, I get the following error message:

"The MIME type or the Extension of the uploaded file image/jpeg was not accepted by the server."

The MimeType value is "image/jpeg", so it should work with the wildcard.

I looked at the wikidocs for the cffile tag and it says this:

ColdFusion 10: Modifications to the attribute accept}}

However, it doesn't elaborate what those modifications are!

Looking at the upload action docs, it says that it will accept a comma delimited list of mime types. Does this mean that wildcards are no longer accepted?

Was it helpful?

Solution

FYI, this blog post has indicated the same problem same time last year:

http://www.cutterscrossing.com/index.cfm/2013/2/21/ColdFusion-10-File-Uploads-and-MIME-Types

Now, I remembered that there were changes to MIME type checking in CF 10, but I wasn't entirely sure. This code, written by one of our developer's several months ago, would allow any "image" MIME type. What we discovered is that we couldn't do this kind of wildcard mapping under CF 10, that we now had to list out each accepted MIME type as a comma delimited list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top