精细上传器与Coldfusion

时间:2013-04-15 16:26:26

标签: coldfusion fine-uploader

尝试在Coldfusion服务器端使用http://fineuploader.com/时出现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>

1 个答案:

答案 0 :(得分:1)

搞定了,我在第二种方法中错过了上传目录路径。

<CFSET UploadDir = "#expandpath('/test/file2')#" > 

感谢您的帮助