我在尝试将 http://fineuploader.com/ 与 Coldfusion 服务器端一起使用时遇到 500 内部服务器错误https://github.com/Widen/fine-uploader-server/tree/master/coldfusion
控制台说:
[FineUploader] 尝试在 window.console.log('<' + level + '> ' + message) 中的这一行解析 xhr 响应文本时出错 (SyntaxError: Unexpected token <);
它似乎来自服务器 CFC 中的响应消息。
<!--- Code provided by Pegasus Web Productions LLC - www.pegweb.com --->
<!--- get stuck use the forums http://github.com/Widen/fine-uploader --->
<!--- Tested with Adobe CF Enterprise 9.x and Fine Uploader --->
<CFCOMPONENT HINT="I do your uploads from Fine Uploader" >
<!--- function for single file submission uploads where XHR is not supported ex:->
<CFFUNCTION NAME="Upload" ACCESS="remote" OUTPUT="false" RETURNTYPE="any" RETURNFORMAT="JSON" >
<CFARGUMENT NAME="qqfile" TYPE="string" REQUIRED="true" />
<CFSET var local = structNew() >
<CFSET local.response = structNew() >
<CFSET local.requestData = GetHttpRequestData() ><!--- get the request headers and body --->
<CFSET UploadDir = "/Test/file2" ><!--- set your upload directory here ex: c:\website\www\images\ --->
<!--- check if XHR data exists --->
<CFIF len(local.requestData.content) GT 0 >
<CFSET local.response = UploadFileXhr(arguments.qqfile, local.requestData.content) >
<CFELSE><!--- no XHR data so process this as standard form submission --->
<!--- upload the file --->
<CFFILE ACTION="upload" FILEFIELD="form.qqfile" DESTINATION="#UploadDir#" NAMECONFLICT="makeunique" >
<!--- populate our structure with information about the image we just uploaded in case we want to use this later for CFIMAGE tags or any other processing --->
<CFSET local.metaData = { clientFile=FILE.clientFile, clientFileExt=FILE.clientFileExt, clientFileName=FILE.clientFileName, contentSubType=FILE.contentSubType, contentType=FILE.contentType, fileSize=FILE.fileSize } />
<!--- return the response --->
<CFSET local.response['success'] = true >
<CFSET local.response['type'] = 'form' >
</CFIF>
<CFRETURN local.response >
</CFFUNCTION>
<!--- function for browsers that support XHR ex: Almost anything but IE --->
<CFFUNCTION NAME="UploadFileXhr" ACCESS="private" OUTPUT="false" RETURNTYPE="struct" >
<CFARGUMENT NAME="qqfile" TYPE="string" REQUIRED="true" />
<CFARGUMENT NAME="content" TYPE="any" REQUIRED="true" />
<CFSET var local = structNew() >
<CFSET local.response = structNew() >
<CFSET UploadDir = "" ><!--- set your upload directory here ex: c:\website\www\images\ --->
<!--- write the contents of the http request to a file. The filename is passed with the qqfile variable --->
<CFFILE ACTION="write" FILE="#UploadDir#\#arguments.qqfile#" OUTPUT="#arguments.content#" NAMECONFLICT="makeunique" >
<!--- populate our structure with information about the image we just uploaded in case we want to use this later for CFIMAGE tags or any other processing --->
<CFSET local.metaData = { clientFile=FILE.clientFile, clientFileExt=FILE.clientFileExt, clientFileName=FILE.clientFileName, contentSubType=FILE.contentSubType, contentType=FILE.contentType, fileSize=FILE.fileSize } />
<!--- return custom JSON if desired--->
<CFSET local.response['success'] = true >
<CFSET local.response['type'] = 'xhr' >
<CFRETURN local.response >
</CFFUNCTION>
调用页面
<div id="thumbnail-fine-uploader">
</div>
<script src="/js/jQueryv1.9.1.js">
</script>
<script src="/Test/file2/jquery.fineuploader-3.4.1.js">
</script>
<script>
$(document).ready(function(){
var thumbnailuploader = new qq.FineUploader({
element: $('#thumbnail-fine-uploader')[0],
request: {
endpoint: 'image-uploader.cfc?method=Upload'
},
multiple: false,
validation: {
allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
sizeLimit: 51200 // 50 kB = 50 * 1024 bytes
},
callbacks: {
onComplete: function(id, fileName, responseJSON){
if (responseJSON.success) {
$('#thumbnail-fine-uploader').append('<img src="img/success.jpg" alt="' + fileName + '">');
}
}
}
});
});
</script>