【问题标题】:Fine Uploader w/ Coldfusion带有 Coldfusion 的精美上传器
【发布时间】:2013-04-15 16:26:26
【问题描述】:

我在尝试将 http://fineuploader.com/ 与 Coldfusion 服务器端 https://github.com/Widen/fine-uploader-server/tree/master/coldfusion 一起使用时遇到 500 内部服务器错误

控制台说:
[FineUploader] 尝试在 window.console.log(' ' + 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>

【问题讨论】:

  • CF 示例是用户贡献的。我对CF不是特别了解。该错误表明您的服务器端代码未返回有效的 JSON 响应。它可能会返回 HTML。能否根据 firebug 或 Chrome 开发者工具粘贴响应的内容?
  • ...另外,这表明您的服务器根本没有正确解析请求并且在此过程中失败。你知道你的服务器端代码到底哪里出错了吗?
  • POST 127.0.0.1:8500/Test/file2/image-uploader.cfc?method=Upload 500 (Internal Server Error) jquery.fineuploader-3.4.1.js:3903 [FineUploader] 尝试解析 xhr 响应文本时出错 (SyntaxError: Unexpected token
  • 所有浏览器都会出现这种情况吗?您使用的是哪个版本的 Fine Uploader?您的客户端代码是什么样的?
  • 看起来我得到了这个响应 qqfilechunk|IMG_2083.JPG|2679388|2000000 值 b43b6ff5-394a-4d43-a571-40b461c5a493|0|0|1041|2681470 我还在上面添加了客户端代码

标签: coldfusion fine-uploader


【解决方案1】:

得到它的工作,我在第二种方法中丢失了我的上传目录路径。

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

感谢您的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 2019-10-29
    • 1970-01-01
    相关资源
    最近更新 更多