收藏
回答

开发者工具中正常使用,但是在手机端却无法使用,直接报错网络错误,返回信息也是有问题

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小程序 Bug Android 10 REMI K80 6.5.3

function uploadFileTwo(img, token = '') {

        reading('show','上传中');

            // 配置参数

        const config = {

            uptoken_url: '/m/base/file/uptoken?type=image',

            domain: window.location.protocol + '//upload.qiniu.com/',

            max_file_size: '100mb',

            max_retries: 3,

            chunk_size: '5mb',  

            filters: {

                mime_types: [

                    {

                        title: 'Image files',

                        extensions: 'jpg,gif,png,bmp,jpeg'

                    }

                ]

            }

        };

        var oData = new FormData();

       

       

        oData.append('name', img.name);

        oData.append('chunk', '0');

        oData.append('chunks', '1');

        oData.append('key', 'app52qno_' + img.name);

        oData.append('token', token);

        oData.append("file", img);

        // console.log(oData)

        // $.MsgBox.Alert('温馨提示','图片上地址是' + config.domain);

        $.ajax({

            url: config.domain,

            type: 'POST',

            data: oData,

            processData: false,

            contentType: false,

            headers: {

                'Authorization': 'Bearer ' + token

            },

            xhr: function() {

                var tmpAjaxXhr = $.ajaxSettings.xhr();

                if (tmpAjaxXhr.upload) {

                    tmpAjaxXhr.upload.addEventListener('progress', function(data) {

                        if (data.lengthComputable) {

                            var tmptotal = Math.floor(data['loaded'] / data['total'] * 100);

                            if (tmptotal == 100) {                              

                                $(".mask_bg .txt").text('处理中')

                            } else {

                                $(".mask_bg .txt").text('上传'+tmptotal+ '%')

                            }

                        }

                    }, false)

                };

                return tmpAjaxXhr

            },

            success: function(res) {

                console.log('File uploaded successfully:', res);

                reading('hide');

                // console.log(res)

                if(res.size){

                    res.path = 'http://slfz4v68k.hd-bkt.clouddn.com/' + res.key;

                    serverImg=  (res.path.indexOf('http') >= 0 ? res.path :  '/Uploads/'+res.path) ;   //https://res.cdn.yqh.com

                    // imgCall(serverImg); // 隐藏手动拖拽

                    $("#img").attr("src",serverImg);    

                    newImgCreate();

                }else{

                    $.MsgBox.Alert('温馨提示','图片上传失败,请稍后再试');

                }

               

                // return res.path;

            },

            error: function(res){

                reading('hide');

                $.MsgBox.Alert('温馨提示','网络错误,请稍后再试!'+ JSON.stringify(res));

            }

        });


    }


function uploadFileTwo(img, token = '') { reading('show','上传中'); // 配置参数 const config = { uptoken_url: '/m/base/file/uptoken?type=image', domain: window.location.protocol + '//upload.qiniu.com/', max_file_size: '100mb', max_retries: 3, chunk_size: '5mb', filters: { mime_types: [ { title: 'Image files', extensions: 'jpg,gif,png,bmp,jpeg' } ] } }; var oData = new FormData(); oData.append('name', img.name); oData.append('chunk', '0'); oData.append('chunks', '1'); oData.append('key', 'app52qno_' + img.name); oData.append('token', token); oData.append("file", img); // console.log(oData) // $.MsgBox.Alert('温馨提示','图片上地址是' + config.domain); $.ajax({ url: config.domain, type: 'POST', data: oData, processData: false, contentType: false, headers: { 'Authorization': 'Bearer ' + token }, xhr: function() { var tmpAjaxXhr = $.ajaxSettings.xhr(); if (tmpAjaxXhr.upload) { tmpAjaxXhr.upload.addEventListener('progress', function(data) { if (data.lengthComputable) { var tmptotal = Math.floor(data['loaded'] / data['total'] * 100); if (tmptotal == 100) { $(".mask_bg .txt").text('处理中') } else { $(".mask_bg .txt").text('上传'+tmptotal+ '%') } } }, false) }; return tmpAjaxXhr }, success: function(res) { console.log('File uploaded successfully:', res); reading('hide'); // console.log(res) if(res.size){ res.path = 'http://slfz4v68k.hd-bkt.clouddn.com/' + res.key; serverImg= (res.path.indexOf('http') >= 0 ? res.path : '/Uploads/'+res.path) ; //https://res.cdn.yqh.com // imgCall(serverImg); // 隐藏手动拖拽 $("#img").attr("src",serverImg); newImgCreate(); }else{ $.MsgBox.Alert('温馨提示','图片上传失败,请稍后再试'); } // return res.path; }, error: function(res){ reading('hide'); $.MsgBox.Alert('温馨提示','网络错误,请稍后再试!'+ JSON.stringify(res)); } }); }
回答关注问题邀请回答
收藏

2 个回答

  • dreamhunter
    dreamhunter
    02-06

    上传域名配置下

    02-06
    有用
    回复
  • Mr.Zhao
    Mr.Zhao
    02-05

    有问题,好歹说一下吧,谁能猜出来啊JSON.stringify(res)

    02-05
    有用
    回复
登录 后发表内容