搜索

首页  >  问答  >  正文

javascript - 七牛js SDK上传问题

我用七牛js skd上传文件,却总是报qiniu.js:663 Uncaught TypeError: Cannot read property 'isExpired' of undefined(…)问题出在plupload,js中
z这是我的代码

var uploader = Qiniu.uploader({
        runtimes: 'html5,flash,html4',
        browse_button: 'pickfiles',
        container: 'container',
        drop_element: 'container',
        max_file_size: '1000mb',
        flash_swf_url: 'bower_components/plupload/js/Moxie.swf',
        dragdrop: true,
        chunk_size: '4mb',
        multi_selection: !(mOxie.Env.OS.toLowerCase()==="ios"),
        //uptoken_url: $('#uptoken_url').val(),
        save_key:false,
        unique_names:false,
        uptoken_func: function(){
            var token;
            $.ajax({
                url:$('#uptoken_url').val(),
                async:false
            }).done(function (data) {

                token= data.result.data.tokenValue;
            });
            return token;
        },
        domain: $('#domain').val(),
        get_new_uptoken: true,
        // downtoken_url: '/downtoken',
        // unique_names: true,
        // save_key: true,
        // x_vars: {
        //     'id': '1234',
        //     'time': function(up, file) {
        //         var time = (new Date()).getTime();
        //         // do something with 'time'
        //         return time;
        //     },
        // },
        auto_start: true,
        log_level: 5,
        init: {
            'FilesAdded': function(up, files) {
                var maxFileSize=1;
                if(up.files.length>maxFileSize){
                    alert("你只能上传一个文件");
                    up.splice(maxFileSize);
                    return;
                }
                $('table').show();
                $('#success').hide();
                plupload.each(files, function(file) {
                    var progress = new FileProgress(file, 'fsUploadProgress');
                    progress.setStatus("等待...");
                    progress.bindUploadCancel(up);
                });
            },
            'BeforeUpload': function(up, file) {
                var progress = new FileProgress(file, 'fsUploadProgress');
                var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
                if (up.runtime === 'html5' && chunk_size) {
                    progress.setChunkProgess(chunk_size);
                }
            },
            'UploadProgress': function(up, file) {
                var progress = new FileProgress(file, 'fsUploadProgress');
                var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
                progress.setProgress(file.percent + "%", file.speed, chunk_size);
            },
            'UploadComplete': function() {
                $('#success').show();
            },
            'FileUploaded': function(up, file, info) {
                var progress = new FileProgress(file, 'fsUploadProgress');
                progress.setComplete(up, info);
            },
            'Error': function(up, err, errTip) {
                $('table').show();
                var progress = new FileProgress(err.file, 'fsUploadProgress');
                progress.setError();
                progress.setStatus(errTip);
            }
        }
    });

这是我从服务端获取token的方法

  public String getToken(Model model){
        AjaxResult result=new AjaxResult();
        String fileName= UUIDGenerator.getUUID();
        QiniuUploadUtils qiniuUploadUtils=new QiniuUploadUtils();
        HashMap token=new HashMap();
        token.put("tokenValue",qiniuUploadUtils.getToken(fileName));
        token.put("file",fileName);
        result.setData(token);
        model.addAttribute("result",result);
        return this.result(ResultType.JSON);
    }
怪我咯怪我咯2773 天前683

全部回复(2)我来回复

  • PHP中文网

    PHP中文网2017-04-11 13:35:39

    是否有公网访问的测试地址?

    回复
    0
  • 大家讲道理

    大家讲道理2017-04-11 13:35:39

    我也出现这个问题。

    前提是你只设置uptoken,并没有设置uptoken_url,然后上传超过你设置的分块大小(默认4M)大小的文件,并且在html5或则flash下,就会触发该报错。

    我认为是官方的bug

    方案一:
    https://github.com/qiniu/js-s...这个链接里面,有暴力解决方案

    方案二:
    把uptoken_url填上

    回复
    0
  • 取消回复