Skip to main content
Inspiring
January 10, 2008
Answered

multipart/form-data and special characters - HELP!!!

  • January 10, 2008
  • 2 replies
  • 5278 views
How can I get a form to work in CF8 that both can upload a file, and submit special characters withot being corrupt. Seems that this cannot be done!!! Try it yourself!

I've even tried <form enctype="multipart/form-data: charset=iso-8859-1">
That solved the problem with the special characters, but it created a new one :(

If I browse a file in my file input field and submit the form, CF gives the following error message:

Invalid content type: application/x-www-form-urlencoded.
The cffile action="upload" requires forms to use enctype="multipart/form-data".

The enctype is ignored, and the default (application/x-www-form) is used instead. If I remove ": charset=iso-8859-1" from the form attribute enctype, the file gets uploaded, but on the other hand, special characters gets corrupt.

I've made a ugly solution where I via javascript before onSubmit appends input text fields and textareas in my form values to the form action value, and the let CF read those variables from the URL scope instead of the FORM scope. Then the special characters will survive, and the image will be uploaded at the same time. But I'm getting tired of this solution. There should be a more simple solution to it. COME ON ADOBE - TELL US!


    This topic has been closed for replies.
    Correct answer yze
    Sorry, didn't mean to yell.
    Has been banging my head agains the wall for a time now, so it was just an expression for my frustration.

    With special characters, I mean for example, åäöü

    I gave it a couple of more hours, and now I've solved it.
    The following was essential to get it work:
    1. The Application.cfm must NOT contain any character encoding settings, such as cfprocessingdirective, and setEncoding (Yes I know, in previously CF-version this was the way to do it, now you shold only include settings at top of every cfm/cfc-file instead)
    2. Use the enctype that you are supposed to use (multipart/form-data) without the extension ": charset=iso-8859-1"
    3. Do NOT use <cfcontent type="text/html; charset=iso-8859-1"> in your cfm-file - that ruined it for me. But you can use <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    4. USE <cfprocessingdirective pageencoding="iso-8859-1"> at top of your cfm-file
    5. There was no need in the cfm-file for either <cfset setEncoding("form","iso-8859-1")> or <cfset setEncoding("url","iso-8859-1")>

    That solved the problem for me.

    System:
    CF8 on xServe (linux)
    CF Admin: Java File Encoding: MacRoman

    2 replies

    Inspiring
    January 10, 2008
    yze wrote:
    > How can I get a form to work in CF8 that both can upload a file, and submit
    > special characters withot being corrupt. Seems that this cannot be done!!! Try

    what are "special characters"? you mean non-ASCII? or what? did you remember to
    set the form encoding (ie setEncoding("form","UTF-8"))?

    can you post your code?

    yzeAuthorCorrect answer
    Inspiring
    January 10, 2008
    Sorry, didn't mean to yell.
    Has been banging my head agains the wall for a time now, so it was just an expression for my frustration.

    With special characters, I mean for example, åäöü

    I gave it a couple of more hours, and now I've solved it.
    The following was essential to get it work:
    1. The Application.cfm must NOT contain any character encoding settings, such as cfprocessingdirective, and setEncoding (Yes I know, in previously CF-version this was the way to do it, now you shold only include settings at top of every cfm/cfc-file instead)
    2. Use the enctype that you are supposed to use (multipart/form-data) without the extension ": charset=iso-8859-1"
    3. Do NOT use <cfcontent type="text/html; charset=iso-8859-1"> in your cfm-file - that ruined it for me. But you can use <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    4. USE <cfprocessingdirective pageencoding="iso-8859-1"> at top of your cfm-file
    5. There was no need in the cfm-file for either <cfset setEncoding("form","iso-8859-1")> or <cfset setEncoding("url","iso-8859-1")>

    That solved the problem for me.

    System:
    CF8 on xServe (linux)
    CF Admin: Java File Encoding: MacRoman
    Inspiring
    January 10, 2008
    yze wrote:
    > COME ON ADOBE - TELL US!

    Before we start yelling at Adobe and lambasting ColdFusion. Are we sure
    this is not a problem with the browser, web server and|or the HTTP
    standard? All of these have a shot at munging your upload before
    ColdFusion gets involved and it is just left with the mess and reports
    the error.

    Unfortunately I do not have time at this time to run any experiments,
    but I think I will look at this in the near future if I can scrape some
    time together.