明明航
明明航
  • 发布:2017-02-27 15:14
  • 更新:2019-06-23 03:29
  • 阅读:4038

【已解决】请问下uploader上传失败是什么原因

分类:HTML5+

更新hbuilder后解决了,醉了,希望越做越好
直接贴代码吧,麻烦帮忙看下,十分感谢

//修改头像,原生模式actionsheet  
document.getElementById("picture").addEventListener('tap', function() {  
    plus.nativeUI.actionSheet({  
        cancel: "取消",  
        buttons: [{  
            title: "拍照"  
        }, {  
            title: "相册"  
        }]  
    }, function(e) {  
        var index = e.index;  
        switch(index) { //case 0: 取消  
            case 1:  
                getImage(); //拍照  
                break;  
            case 2:  
                appendByGallery(); //相册  
                break;  
        }  
    });  
});  
// 拍照添加文件  
function getImage() {  
    var cmr = plus.camera.getCamera();  
    cmr.captureImage(function(p) {  
        plus.io.resolveLocalFileSystemURL(p, function(entry) {  
            var localurl = entry.toLocalURL(); //把拍照的目录路径,变成本地url路径,例如file:///........之类的。  
            compressImage(localurl);  
        });  
    }, function(error) {  
        alert("Capture image failed: " + error.message);  
    });  
}  
// 从相册添加文件   
function appendByGallery() {  
    plus.gallery.pick(function(path) {  
        compressImage(path); //处理图片的地方  
    });  
}  
//压缩图片  
function compressImage(imgsrc) {  
    var dst_img = "_documents/a"+Math.round(Math.random()*100)+".jpg";  
    plus.zip.compressImage({  
        src: imgsrc,  
        dst: dst_img,  
        overwrite: true,  
        width:"500px"  
    },  
    function(e) {  
        createUpload(e.target,dst_img, e.height);  
    },  
    function(error) {  
        alert("Compress error!" + JSON.stringify(error));  
    });  
}  
//上传源文件  
function createUpload(path) {  
    plus.nativeUI.showWaiting();**//一直卡在这里**  
    var task = plus.uploader.createUpload(loadimg,   
        { method:"POST"},  
        function ( t, status ) {  
            // 上传完成  
            plus.nativeUI.closeWaiting();  
            if ( status == 200 ) {  
                //console.log(t.responseText);  
                var location_user_img = t.responseText.replace(/\//g,"");  
                $("#picture").attr("src",path);  
                lset("user_picture",path);  
                var ws = plus.webview.currentWebview();  
                wo = ws.opener();  
                wo.evalJS("info_shuaxin('"+path+"')");  
            } else {  
                alert( "Upload failed: " + status );  
            }  
        }  
    );  
    task.addData('token', token);  
    task.addFile(path, {key:"image"});  
    task.start();  
}
2017-02-27 15:14 负责人:无 分享
已邀请:
明明航

明明航 (作者) - 你好

有人知道吗?我发现h5+的uploader也用不了。。。是我的问题吗?换了两个iphone手机了

  • 明明航 (作者)

    求帮忙啊

    2017-02-27 17:23

明明航

明明航 (作者) - 你好

求助啊

1***@qq.com

1***@qq.com

手机上需要注意的是要确保局域网能够正常访问,在电脑上ping或者在手机上访问电脑ip,本人上传失败主要是这个问题,ip地址没有改,导致reponseText结果为refuse connect

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