zoukankan      html  css  js  c++  java
  • 小程序上传图片的大坑

    data: {
        imgurl:''
      },
    
      chooseImage1(){
        var that = this;
        wx.chooseImage({
          count: 1,
          sizeType: ['original', 'compressed'],
          sourceType: ['album', 'camera'],
          success(res) {
            const tempFilePaths = res.tempFilePaths[0]
    
            wx.uploadFile({
              url: 'https://。。。。。。。/imageUpload', //开发者服务器的 url
              filePath: tempFilePaths, // 要上传文件资源的路径 String类型!!!
                 name: 'img', // 文件对应的 key ,(后台接口规定的关于图片的请求参数)
                 header: {
                     'content-type': 'multipart/form-data',
                      'token': wx.getStorageSync('token')
                 }, // 设置请求的 header
                 formData: {}, // HTTP 请求中其他额外的参数
                 success: function (res) {
                   console.log(res.data);
                   var ob = JSON.parse(res.data);
                   console.log(ob)
                   that.setData({
                     imgurl: 'https://。。。。。/'+ob.data
                   })
                 },
                 fail: function (res) {
                 }
              })
          }
        })
      }
    

      上传图片代码就是上面的这些,但是会出现有时候能上传上去有时候不能,原来是小程序做了限制,大概在2m以内

    大家觉得不错的话可以支持一下

  • 相关阅读:
    windows下安装各种python包
    error?
    PBS error
    samtools error
    samtools idxstats
    maf error
    tba error
    基因组拼接中常见的名词解释
    Spring could使用FeignClient超时问题
    sql在指定列后添加或删除字段
  • 原文地址:https://www.cnblogs.com/xiangxiang521/p/10109895.html
Copyright © 2011-2022 走看看