Wells
Wells
  • 发布:2017-06-16 17:42
  • 更新:2017-06-16 17:42
  • 阅读:2035

【报Bug】plus.uploader.createUpload出错

分类:HTML5+

详细问题描述
[内容]
Hbuilder升级到8.8.0.201706142254以后,用plus.uploader上传文件后台要报错,同样的后台用其他方式(比如web)不会出错,升级以前也不出错。
重现步骤
[步骤]
1、升级Hbuider
2、做一个文件上传的例子,用plus.uploader上传图片
[结果]
后台报错,错误内容:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
[期望]
上传成功
运行环境
[系统版本]
win10
[浏览器版本]
Firefox54.0
[IDE版本]
HBuilder
8.8.0.201706142254
[mui版本]
Mui v3.7.0
附件
[代码片段]
//添加图片附件
var attach = new Array();
var maxSize = 510241024;
//从相机获取
function getImage() {
showsheet();
var cmr = plus.camera.getCamera();
cmr.captureImage(function(p) {
plus.io.resolveLocalFileSystemURL(p, function(entry) {
entry.getMetadata(function(metadata) {
if(maxSize < metadata.size){
plus.nativeUI.toast("图片超过5M,建议降低照片精度后拍照");
}else{
//添加到附件列表
createItem(entry);
}
});
}, function(e) {
plus.nativeUI.toast("打开摄像图失败:" + e.message);
});
}, function(e) {
console.log("失败:" + e.message);
}, {
filename: "_doc/camera/",
index: 1
});
}
//从相册选取图片
function getPhoto() {
mui('#attachsheet').popover('hide');
plus.gallery.pick(function(p) {
plus.io.resolveLocalFileSystemURL(p, function(entry) {
entry.getMetadata(function(metadata) {
if(maxSize<metadata.size){
plus.nativeUI.toast("图片超过5M,建议压缩后上传");
}else{
createItem(entry);
}
});

        }, function(e) {  
            plus.nativeUI.toast("打开相册失败:" + e.message);  
        });  
    });  
}  
//添加到附件列表  
function createItem(entry) {  
    if(attach.length < 3){  
        var at = {};  
        at.path = entry.fullPath;  
        at.name = entry.name;  
        attach.push(at);      
        if(attach.length == 1){  
            mui("#attachlist")[0].innerHTML = "";  
        }   
        var a = document.createElement("a");  
        //"<a class='item'><div class='avatar'><img src='"+entry.fullPath+"'/></div><div class='title'>"+entry.name+"</div></a>"  
        a.className = "item";                       
        a.setAttribute("onclick","delfile(this, '" + entry.fullPath + "', '" + entry.name + "')");            
        a.innerHTML = "<div class='avatar'><img src='"+entry.fullPath+"'/></div><div class='title'>"+entry.name+"</div><i class='icon icon-trash text-danger'></i>";  
        //console.log(a.outerHTML);  
        mui("#attachlist")[0].insertBefore(a);  
    } else {  
        mui.toast("附件过多,三个比较合适");  
    }         
}  

//保存日志  
function savelog(){  
    var p_l = {};  
    p_l.cmd = "app";  
    p_l.opt = "savelog";  
    p_l.taskid = plus.webview.currentWebview().taskid;  
    p_l.log = $("#log").val().trim();  
    p_l.pics = attach;  
    if(p_l.log == ''){  
        $("#log").focus();  
    } else {  
        var wt = plus.nativeUI.showWaiting("上传附件...");      
        var task = plus.uploader.createUpload(  
            localStorage.getItem("server") + "/upload",   
            {method: "POST"},  
            function(t, status) { //上传完成  
                if (status == 200) {  
                    var xresult = JSON.parse(t.responseText);  
                    for (var fileIndex = 0; fileIndex < xresult.length; fileIndex++) {  
                        var resultItem = xresult[fileIndex];  
                        if (resultItem.optflag == false) {  
                            plus.nativeUI.toast("附件上传失败:" + resultItem.msg);   
                            wt.close();  
                            return;  
                        }  
                    }  
                    //成功后,准备提交表单  
                    var filelistr = JSON.parse(t.responseText);  
                    var attachment = new Array();  
                    for (var ix = 0; ix < filelistr.length; ix++) {  
                        attachment.push(filelistr[ix].filename);  
                    }  
                    p_l.pics = attachment;  
                    wt.close();  
                    wt = plus.nativeUI.showWaiting("记录工作日志...");  
                    //提交表单数据  
                    mui.ajax(localStorage.getItem("server") + "/appback", {  
                        data: {  
                            parms: JSON.stringify(p_l),  
                        },  
                        dataType: 'json',   
                        type: 'post',  
                        timeout: 5000,  
                        headers: {'Content-Type':'application/x-www-form-urlencoded; charset=utf-8'},//解决地址里面的中文乱码    
                        success: function(data) {  
                            if (data.success) {  
                                wt.close();  
                                plus.nativeUI.alert("工作日志记录成功。",function(){  
                                    mui.back();  
                                },"任务提示","确定");                                   
                            } else {  
                                plus.nativeUI.toast(data.errmessage,{  
                                    duration: 'long'                              
                                });  
                                if(data.rstcode == "-9") {  
                                    setTimeout(function() {  
                                        mui.openWindow({  
                                            url: "../index.html",  
                                            id: "login"                     
                                        });  
                                    }, 2000);  
                                }  
                            }  
                        },  
                        error: function(xhr, type, errorThrown) {  
                            wt.close();  
                            if(type == 'timeout'){  
                                type = "访问服务器超时...";  
                            }  
                            plus.nativeUI.toast(type);  
                        }  
                    });  
                } else {  
                    wt.close();  
                }  
            }  
        );  
        for(var i = 0; i < attach.length; i++) {  
            task.addFile(attach[i].path, {key: attach[i].name});                  
        }  
        task.start();  
    }  
}     

[安装包]

联系方式
[QQ]6536310
[电话]

2017-06-16 17:42 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复