Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用requirejs后的getOption 错误 #6

Closed
MarchLiu opened this issue Apr 2, 2014 · 5 comments
Closed

使用requirejs后的getOption 错误 #6

MarchLiu opened this issue Apr 2, 2014 · 5 comments

Comments

@MarchLiu
Copy link

MarchLiu commented Apr 2, 2014

这里使用了requirejs 。

requirejs.config({
    appDir:"/static/js",
    paths:{
        'jquery':"/static/bower_components/jquery/dist/jquery.min",
        "plupload":"/static/bower_components/plupload-bower/js/plupload.full",
        "qiniu":"/static/js/qiniu"
    },
    shim:{
        'plupload':{"exports":"plupload"},
        'qiniu':{"exports":"Qiniu"}
    }
})

require(["jquery", "plupload", "qiniu"],
    function($, plupload, qiniu){
        var uploader = qiniu.uploader({
            runtimes:"html5",
            browse_button:"pickfiles",
            uptoken_url:"/api/qiniu/uptoken/tratao",
            domain:"tratao.qiniu.com",
            container:"container",
            max_retries:3,
            dragdrop:true,
            drop_element:container,
            chunk_size: '4mb',
            auto_star:true,
            init:{
                'FilesAdded': function(up, files) {
                    console.log(up)
                    plupload.each(files, function(file) {
                        //文件添加进队列后,处理相关的事情
                    });
                },
                'BeforeUpload': function(up, file) {
                    //每个文件上传前,处理相关的事情
                },
                'UploadProgress': function(up, file) {
                    //每个文件上传时,处理相关的事情
                },
                'FileUploaded': function(up, file, info) {
                    //每个文件上传成功后,处理相关的事情
                    //其中 info 是文件上传成功后,服务端返回的json,形式如
                    // {
                    //    "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
                    //    "key": "gogopher.jpg"
                    //  }
                    // 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html

                   // var domain = up.getOption('domain');
                   // var res = parseJSON(info);
                   // var sourceLink = domain + res.key; 获取上传成功后的文件的Url
               },
               'Error': function(up, err, errTip) {
                   //上传出错时,处理相关的事情
               },
               'UploadComplete': function() {
                   //队列文件处理完毕后,处理相关的事情
               }
            }
        }
    )}
)

提示 qiniu.js:283 错误,up.getOption 不存在。看了一下log出来的up对象,确实没有。这里应该是requirejs做shim设定的时候制定的plupload对象不对。

@MarchLiu
Copy link
Author

MarchLiu commented Apr 2, 2014

2014-04-02 7 29 53

@MarchLiu
Copy link
Author

MarchLiu commented Apr 2, 2014

试了一下,是bower 安装的 plupload-bower 版本太低,用 bower install plupload 后这个问题解决……虚惊……

@MarchLiu MarchLiu closed this as completed Apr 2, 2014
@SunLn
Copy link
Contributor

SunLn commented Apr 2, 2014

刘老师解决了就好。多谢关注啊。

@SunLn
Copy link
Contributor

SunLn commented Apr 2, 2014

刘老师的问题反映了SDK内部对plupload的版本依赖检测不成熟,另外我们的文档也没有明确plupload的版本。已经提了修复的issue,会及时跟进。

@MarchLiu
Copy link
Author

MarchLiu commented Apr 4, 2014

这其实是plupload做的比较欠啊……两个版本差好多,而且bower下来的介绍也挺误导人的。仔细看了一下官网才发现版本不对,再一对比2.x多了很多东西。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants