首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带Coldfusion的Fine Uploader

带Coldfusion的Fine Uploader
EN

Stack Overflow用户
提问于 2013-04-16 00:26:26
回答 1查看 1.1K关注 0票数 0

在Coldfusion服务器端https://github.com/Widen/fine-uploader-server/tree/master/coldfusion中使用http://fineuploader.com/时,我遇到了一个500内部服务器错误

控制台显示:

试图在window.console.log('<‘+ level + '>’+message)中的此行解析xhr响应文本(SyntaxError:意外标记<)时出现FineUploader错误;

它似乎来自于服务器CFC中的响应消息。

代码语言:javascript
复制
<!--- 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>

调用页面

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

发布于 2013-04-16 16:52:48

让它正常工作,我在第二个方法中缺少上传目录路径。

代码语言:javascript
复制
<CFSET UploadDir = "#expandpath('/test/file2')#" > 

谢谢你的帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16020183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档