• uniapp:OCR识别身份证上传原图失败,问题解决


    1、上传普通图片成功
    2、上传>4M | >5M图片失败
    检查:
    1、uni.uploadFile自身没有文件大小限制。然而,这仍然取决于你的应用程序所在的平台和存储空间容量。

    2、上传照片后不在fail,在sucess

    1. 提交照片-3 {"data": "<html>
    2. \n<head><title>413 Request Entity Too Largetitle>head>
    3. \n<body>
    4. \n<center><h1>413 Request Entity Too Largeh1>center>
    5. \n<hr><center>nginx/1.18.0 (Ubuntu)center>
    6. \nbody>
    7. \nhtml>
    8. \n
    9. \n
    10. \n
    11. \n
    12. \n
    13. \n
    14. \n", "header": {"Server": "nginx/1.18.0 (Ubuntu)", "Connection": "close", "Content-Length": "594", "Date": "Thu, 14 Sep 2023 04:56:41 GMT", "Content-Type": "text/html", "protocol": "http/1.1"}, "statusCode": 413, "cookies": [], "errMsg": "uploadFile:ok"}

    总结:
    由上面2处结果分析:问题在于 服务器,由后端解决

    其他知识:

    1、上传文件大小限制:
    uni.chooseImage得到的文件大小单位为B(既是字节),换算成M:
     

    1. success: (res) => {
    2. let filePath = res.tempFilePaths[0];
    3. let fileSize = res.tempFiles[0].size / 1024 / 1024
    4. let isNext = true;
    5. if (fileSize >= 10) {
    6. isNext = false
    7. }
    8. if (!isNext) {
    9. uni.showToast({
    10. title: '存在文件超过10M,暂不支持上传',
    11. icon: 'none',
    12. duration: 8000
    13. })
    14. return
    15. }
    16. ...
    17. }

    2、 文件太大,上传进度让人模糊

    1. const uploadTask = uni.uploadFile({
    2. url: url,
    3. filePath: filePath,
    4. header: {
    5. "Authorization": 'Bearer ' + this.vToken
    6. },
    7. name: name,
    8. ...
    9. });
    10. uploadTask.onProgressUpdate((res) => {
    11. // console.log('上传进度' + res.progress);
    12. // console.log('已经上传的数据长度' + res.totalBytesSent);
    13. // console.log('预期需要上传的数据总长度' +res.totalBytesExpectedToSend);
    14. if (res.progress < 99) {
    15. // 测试条件,取消上传任务。
    16. // uploadTask.abort();
    17. uni.showLoading({
    18. title: '上传中'
    19. })
    20. } else {
    21. uni.hideLoading()
    22. }
    23. });

    3、文件上传时间久,可能会断传
    uniapp解决办法:uni网络请求超时时间设置

     

    相关uni文档:https://uniapp.dcloud.io/collocation/manifest?id=networktimeout

    如图所示,请求超时的默认时间均为6000毫秒,可根据自己的需求在 manifest.json 的 源码视图 里面更改。
    设置完成后,服务需重启才能生效!
     

    1. "networkTimeout":{
    2. "request":30000,
    3. "uploadFile":60000,
    4. "downloadFile":60000
    5. }

  • 相关阅读:
    基于ssm+vue的研究生推免报名面试系统 计算机毕业设计
    python GUI(五)预设弹窗介绍
    python过滤非法字符
    Java项目:SSM电影售票管理系统
    了解一下Monorepo
    GPU不够用:语言模型的分布式挑战
    Leetcode 283. Move Zeroes
    端口映射与容器互联
    从QGIS图层中裁剪需要的区域
    【Redis】Hash类型
  • 原文地址:https://blog.csdn.net/weixin_63456913/article/details/132876368