Title:
Bug 75723:(Watson Migration Closure)add capability for CFAJAXPROXY to let send form data with multipart/form-data enctype
| View in TrackerStatus/Resolution/Reason: Closed/Deferred/
Reporter/Name(from Bugbase): Jefferson Petilo / Jefferson Petilo (Jeff Petilo)
Created: 02/27/2009
Components: AJAX, UI Components
Versions: 9.0
Failure Type: Unspecified
Found In Build/Fixed In Build: 0000 /
Priority/Frequency: Normal / Unknown
Locale/System: English / Platforms All
Vote Count: 0
Problem:
add capability for CFAJAXPROXY to let send form data with multipart/form-data enctype. This feature is very usefull to able to upload files using ajax. In CF8, on the cfajax.js the enctype header is always overridden by application/x-www-form-urlencoded.
Method:
<!--creating Upload Class C:\ColdFusionCentaur\wwwroot\upload.cfc-->
<cfcomponent displayname="Upload test with CFAjaxProxy">
<cffunction name="upload" access="public" output="false" returntype="struct">
<cfargument name="variable" type="string" required="true"/>
<cfargument name="destination" type="string" required="true"/>
<cfset var strReturn = structNew()/>
<cftry>
<cffile action ="upload" attributeCollection="#ARGUMENTS#"/>
<cfset strReturn.message = 'File was uploaded sucessfully!'/>
<cfset structAppend(strReturn,CFFILE,true)/>
<cfcatch type="any">
<cfset strReturn.message = 'Error when system was send the file ' & CFCATCH.Detail/>
<cfset structAppend(strReturn,CFCATCH,true) />
</cfcatch>
</cftry>
<cfreturn strReturn/>
</cffunction>
</cfcomponent>
<!-- C:\ColdFusionCentaur\wwwroot\uploadCaller.cfc-->
<cfcomponent displayname="Upload Caller">
<cffunction name="actUploadFile" output="false" access="remote" returntype="struct">
<cfset var strFile = createObject("component","upload").upload(variable='myfile',destination='C:\ColdFusionCentaur\wwwroot')/>
<cfreturn strFile/>
</cffunction>
</cfcomponent>
<!-- C:\ColdFusionCentaur\wwwroot\cfajaxproxy_cffile.js-->
var instance = new uploadCaller();
instance.setForm('form_upload');
instance.setHTTPMethod('POST');
instance.setCallbackHandler(callbackResult);
instance.setErrorHandler(errorHandler);
function uploadFileAjax(){
instance.actUploadFile();
}
var callbackResult = function(result){
alert(result.MESSAGE);
}
var errorHandler = function(statusCode,statusMsg) {
alert('Error:'+ statusCode + ' - ' + statusMsg);
}
<!-- C:\ColdFusionCentaur\wwwroot\form_upload_cfajaxproxy.cfm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="cfajaxproxy_cffile.js"></script>
<cfajaxproxy cfc="uploadCaller" jsclassname="uploadCaller" />
</head>
<body id="body">
<div id="formContainer">
<form name="form_upload" id="form_upload" enctype="multipart/form-data" action="" method="post">
<p>
<label>Foto : </label>
<input type="file" name="myfile" id="myfile" />
<br class="hid" />
<input type="button" name="SendFile" value="SendFile" onClick="uploadFileAjax()"/>
</p>
</div>
</body>
</html>
Result:
{"Detail":"The cffile action=\"upload\" requires forms to use enctype=\"multipart\/form-data\".","MESSAGE"
:"Invalid content type: application\/x-www-form-urlencoded; charset=UTF-8.","CType":"application\/x-www-form-urlencoded
; charset=UTF-8","TagContext":[{"ID":"CFFILE","COLUMN":0,"TEMPLATE":"C:\\ColdFusionCentaur\\wwwroot\upload.cfc","RAW_TRACE":"\tat cfupload2ecfc159241784$funcUPLOAD.runFunction(C:\\ColdFusionCentaur\\wwwroot
\\upload.cfc:9)","TYPE":"CFML","LINE":9},{"ID":"CF_TEMPLATEPROXY","COLUMN":0,"TEMPLATE":"C:\\ColdFusionCentaur
\\wwwroot\\uploadCaller.cfc","RAW_TRACE":"\tat cfuploadCaller2ecfc25968101$funcACTUPLOADFILE.runFunction
(C:\\ColdFusionCentaur\\wwwroot\\uploadCaller.cfc:3)","TYPE":"CFML","LINE":3}],"Type":"Application","StackTrace"
:"coldfusion.tagext.io.FileTag$CFFileNonMultipartException: Invalid content type: application\/x-www-form-urlencoded
; charset=UTF-8.\r\n\tat coldfusion.tagext.io.FileTag.upload(FileTag.java:569)\r\n\tat coldfusion.tagext
.io.FileTag.doStartTag(FileTag.java:268)\r\n\tat cfupload2ecfc159241784$funcUPLOAD.runFunction(C:\\ColdFusionCentaur
\\wwwroot\\upload.cfc:9)\r\n\tat coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:424)\r\n\tat coldfusion
.filter.SilentFilter.invoke(SilentFilter.java:47)\r\n\tat coldfusion.runtime.UDFMethod$ReturnTypeFilter
.invoke(UDFMethod.java:357)\r\n\tat coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod
.java:320)\r\n\tat coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)\r\n\tat
coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:274)\r\n\tat coldfusion.runtime.UDFMethod
.invoke(UDFMethod.java:469)\r\n\tat coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:512)\r
\n\tat coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:336)\r\n\tat coldfusion.runtime.CfJspPage
._invoke(CfJspPage.java:2268)\r\n\tat cfuploadCaller2ecfc25968101$funcACTUPLOADFILE.runFunction(C:\\ColdFusionCentaur
\\wwwroot\\uploadCaller.cfc:3)\r\n\tat coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:424)\r\n\tat
coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)\r\n\tat coldfusion.runtime.UDFMethod$ReturnTypeFilter
.invoke(UDFMethod.java:357)\r\n\tat coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod
.java:320)\r\n\tat coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)\r\n\tat
coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:274)\r\n\tat coldfusion.runtime.UDFMethod
.invoke(UDFMethod.java:469)\r\n\tat coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:512)\r
\n\tat coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:336)\r\n\tat coldfusion.filter.ComponentFilter
.invoke(ComponentFilter.java:183)\r\n\tat coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter
.java:295)\r\n\tat coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)\r\n\tat
coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)\r\n\tat coldfusion.filter.PathFilter
.invoke(PathFilter.java:86)\r\n\tat coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70
)\r\n\tat coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28
)\r\n\tat coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)\r\n\tat coldfusion.filter.NoCacheFilter
.invoke(NoCacheFilter.java:46)\r\n\tat coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
\r\n\tat coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)\r\n\tat coldfusion.xml.rpc
.CFCServlet.invoke(CFCServlet.java:138)\r\n\tat coldfusion.xml.rpc.CFCServlet.doPost(CFCServlet.java
:289)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:760)\r\n\tat org.apache.axis.transport
.http.AxisServletBase.service(AxisServletBase.java:327)\r\n\tat javax.servlet.http.HttpServlet.service
(HttpServlet.java:853)\r\n\tat coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89
)\r\n\tat jrun.servlet.FilterChain.doFilter(FilterChain.java:86)\r\n\tat coldfusion.monitor.event.MonitoringServletFilter
.doFilter(MonitoringServletFilter.java:42)\r\n\tat coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter
.java:46)\r\n\tat jrun.servlet.FilterChain.doFilter(FilterChain.java:94)\r\n\tat jrun.servlet.FilterChain
.service(FilterChain.java:101)\r\n\tat jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)\r
\n\tat jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)\r\n\tat jrun.servlet.JRunRequestDispatcher
.invoke(JRunRequestDispatcher.java:286)\r\n\tat jrun.servlet.ServletEngineService.dispatch(ServletEngineService
.java:543)\r\n\tat jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)\r\n\tat jrunx.scheduler
.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)\r\n\tat jrunx.scheduler.ThreadPool$ThreadThrottle
.invokeRunnable(ThreadPool.java:428)\r\n\tat jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable
(ThreadPool.java:266)\r\n\tat jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)\r\n"}
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3037703
External Customer Info:
External Company:
External Customer Name: Jefferson Petilo
External Customer Email: 05066099465874BC992015A8
External Test Config: 02/27/2009
Attachments:
Comments: