首页 > 其他分享 >uniapp接口获取文件流

uniapp接口获取文件流

时间:2023-07-31 10:06:21浏览次数:39  
标签:uniapp 文件 res arraybuffer xxx 接口 获取 arrayBufferToBase64 uni

默认的request请求是JSON格式

responseType: 'arraybuffer',我们可以设置 arraybuffer

这样就可以拿到文件流了,案例的文件流是bas64格式

uni.request({
      url: "https://xxx.xxx.cn/bank/file/xxx/aeb9beb4fb2444ff80d47ed11c18b991.jpg",
      method: 'GET',
      responseType: 'arraybuffer',
      
      success: res => {
        let datas = res.data;
        this.codeUrl =  'data:image/png;base64,'+uni.arrayBufferToBase64(datas);
      },
    });

主要就是将响响应的数据类型修改成 arraybuffer

最后使用uni.arrayBufferToBase64()方法将 ArrayBuffer 对象转成 Base64 字符串

<image :src="`${codeUrl}`"  ></image>

这样就可以获取文件流使用文件流了

标签:uniapp,文件,res,arraybuffer,xxx,接口,获取,arrayBufferToBase64,uni
From: https://blog.51cto.com/u_16204378/6905424

相关文章

  • javaee 创建泛型类 泛型接口
    泛型类packagecom.test.generic;//泛型类publicclassBox<T>{ privateTt; publicTgetT(){ returnt; } publicvoidsetT(Tt){ this.t=t; } publicBox(Tt) { this.t=t; }}泛型接口packagecom.test.generic;//泛型接口publicinterface......
  • windows 获取系统中所有应用程序
    前言:  记录下。重点    RegistryView.Registry64与RegistryView.Registry32。有些程序在Registry64中,有些程序在Registry32中。 代码查看代码varlocalMachine=RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,RegistryView.Registry64......
  • web APIs获取dom元素
    1.获取页面中的标签最常用的两种方式 document.querySelectorAll和document.querySelector 2他们两个区别是什么document.querySelectorAll可以选择多个元素,得到伪数组,要遍历才能得到每一个元素document.querySelector只能得到一个元素,可以直接操作注意:它们里面的小括......
  • uniapp Ucharts 横向bar图 每个设置颜色不同
    代码-------》》》arr=[80,80,80]letvalueList=arr.map((item,index)=>{ letcolor='' letnewNumber=Number(item) if(index==0)color='#5593FE' if(index==1)color='#93b6f8' if(ind......
  • python数据分析师入门-学习笔记(第十节 数据获取)
    工具使用Anaconda官网下载安装一路next(默认就行)Chrome默认安装就行打开jupyternotebook打开anacondaprompt输入jupyternotebook系统自动打开一个网页快手掌握开发工具模式:代码模式markdown模式快捷键h查看所有快捷键esc编辑状态切换......
  • uniapp 移动端axisLabel 设置formatter无效的解决方法
    pc端是直接在option里配置移动端在renderjs里的监听变化的时候去设置updateEcharts(newValue,oldValue,ownerInstance,instance){//监听service层数据变更try{newValue.xAxis.axisLabel.formatter=function(......
  • uniapp中使用i18n
    1.安装vue-i18n 2.根目录下新建locale文件夹,创建index.jsimport{createI18n}from'vue-i18n'importenfrom'./en.json'//locale文件夹下的英文配置importzhfrom'./zh.json'//中文配置importzhFanfrom'./zh-fan.json'//繁体配置const......
  • Locust 压测socket接口样例
    importsocketfromlocustimportUser,task,between,constantclassSocketUser(User):#初始化,建立Socket连接defon_start(self):self.client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)self.client.connect(('localhost',8080))#替换为目标Socket服务......
  • Revit二次开发-获取族类型以及族参数值
      在族环境中获取当前族的所有族类型以及族类型对应的所有参数和参数值。直接上代码~publicoverrideResultExecute(ExternalCommandDatacommandData,refstringmessage,ElementSetelements){vardoc=commandData.Application.ActiveUIDocument......
  • java使用线程池实现接口自动化中的并发测试
    importjava.util.concurrent.ExecutionException;importjava.util.concurrent.ExecutorService;importjava.util.concurrent.Executors;importjava.util.concurrent.Future;publicvoidtest()throwsExecutionException,InterruptedException{ExecutorServ......