zoukankan      html  css  js  c++  java
  • 小程序的buffer转图片

    项目中小程序遇到大图片生成的需求,需要传递一个参数,然后从服务端获取生成到的长图。微信本身的wx.download()只提供Get请求,不提供POST请求方式下载。所以使用wx.request请求到arraybuffer存入本地文件。


    wx.request({
    
            url: pathUrl,//请求地址
    
            method: 'POST',//POST方式
    
            data: params,//附加参数
    
            responseType: 'arraybuffer',//响应方式
    
            header: {
    
              'content-type': 'application/x-www-form-urlencoded'//我们服务器都是form
    
            },
    
            success(res) {
    
              console.log(res.statusCode)
    
              console.log(res.data)
    
              let fileManager = wx.getFileSystemManager();//获取文件管理器
    
              let filePath = wx.env.USER_DATA_PATH + '/inner.jpg';//设置临时路径
    
              fileManager.writeFile({//获取到的数据写入临时路径
    
                filePath: filePath,//临时路径
    
                encoding: 'binary',//编码方式,二进制
    
                data: res.data,//请求到的数据
    
                success: function(res) {
    
                  console.log(res)
    
                  console.log(filePath)//打印路径
    
                  wx.previewImage({//图片预览
    
                    urls: [filePath],
    
                  })
    
                  wx.hideLoading();
    
                },
    
                fail: function(res) {
    
                  console.log(res)
    
                  wx.hideLoading();
    
                },
    
              });
    
            }
    
          })

    转 : https://www.jianshu.com/p/45e87673d5c6

  • 相关阅读:
    z-index只能在position属性值为relative或absolute或fixed的元素上有效。
    margin负值得理解
    <em>标签与<strong>标签区别
    文字的垂直居中
    data-*的定义和用法
    one()方法的介绍
    <meta name="application-name" content="优酷网" /> 是什么意思?
    <meta property="qc:admins" content="70003766576320416375" />是什么意思?具体功能是什么?
    head部分关于搜索引擎
    java第三次作业
  • 原文地址:https://www.cnblogs.com/fps2tao/p/12610931.html
Copyright © 2011-2022 走看看