如图所示:

上传图片,使用的是uni.chooseImage这个官方api,count 数量根据自己的需求来,我们是最多只能上传9张

          uploadImgEvent(){
uni.chooseImage({
count: 10 - this.uploadImgsList.length,
success: (res) => {
this.uploadImgsList.unshift(...res.tempFiles.map(item => ({
picturePath: item.path
})));
if(this.uploadImgsList.length == 10) this.uploadImgsList.pop();
}
});
},
uploads(){
const _this = this;
return Promise.all(_this.uploadImgsList.map(item=>_this.uploadImage(item.picturePath))).then(res=>{
return res.map(item=>({
fileName:item.fileName,
filePath:item.url
}))
})
},
uploadImage(url) {
return new Promise(async (resolve, reject) => {
uni.uploadFile({
url: await getUploadUrl(), //后台地址
filePath: url,
name: 'file',
success: (uploadFileRes) => {
resolve(JSON.parse(uploadFileRes.data));
}
})
})
},

提交给后代的数据

//提交
async submitFlood(){
  let photoList = await this.uploads();
}
打印photoList如图:

上传文件使用的LFile 这个插件 https://ext.dcloud.net.cn/plugin?id=4109

根据官网案例来

         //上传附件
uploadFile() {
const that = this;
if(that.imgUploadList.length >= 9){
this.$mHelper.toast('最多上传9张')
return;
}
that.$refs.lFile.upload({
// #ifdef APP-PLUS
currentWebview: that.$mp.page.$getAppWebview(),
// #endif
url: 'xxxxxx', //你的上传附件接口地址
name: 'file'
},
});
},
         //上传成功
upSuccess(res) {
let url = res.root.url;
let name = res.root.originalName;
let fileType = this.isFileType(res.root.type);
let size = res.root.size;
if(fileType == 'image'){
this.imgUploadList.push({url,name,fileType,size});
}else{
this.fileUploadList.push({url,name,fileType,size})
}
},
//根据文件后缀名来判断,展示对应的图标
isImage(type){
return ['png','jpg','jpeg','gif','svg'].includes(type.toLowerCase());
},
isDocx(type){
return ['doc','docx'].includes(type.toLowerCase());
},
isXsls(type){
return ['xsls','xsl'].includes(type.toLowerCase());
},
isText(type){
return ['text','txt'].includes(type.toLowerCase());
},
isFileType(type){
if(this.isImage(type)) return 'image';
if(this.isXsls(type)) return 'excel';
if(type == 'pdf') return 'pdf';
if(this.isDocx(type)) return 'word';
if(this.isText(type)) return "text";
// return "#icon-file-b--6";
},
//文件预览
previewFile(item){
uni.downloadFile({
url: item.url,
success: (res) => {
let filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
success: (res) => {
console.log('打开文档成功');
}
})
}
})
},

uni-app上传图片和文件的更多相关文章

  1. web app上传图片

    很就很久以前,web app上传图片需要通过cordova插件,那时候好像还叫phonegap. 后来一个html标签就可以了 <input type="file" clas ...

  2. Ionic app 上传图片之webApi接口

    App上传图片对应的webApi服务端是怎么处理的呢? using System; using System.Collections.Generic; using System.Diagnostics ...

  3. flask上传图片或者文件

    在flask unittest自动化测试中如何上传图片或者文件 import StringIO picture = StringIO.StringIO(open('/home/admin/Pictur ...

  4. 查看真机的APP沙盒文件

    1.Xcode --> window --> devices -->左边选择设备 右下边选择要查看的app 双击应用可查看目录 点击设置按钮,选 Download Container ...

  5. 用AJAX实现上传图片或者文件的方法

    大家好,我是小C,最近在项目中用到ajax上传图片文件,本篇我们就说说ajax上传文件. 我们平时用到的AJAX,大部分都是传几个参数就可以了.简单说就是传几个字符串. $.ajax({ url: u ...

  6. sau交流学习社区--在element-ui中新建FormData对象组合上传图片和文件的文件对象,同时需要携带其他参数

    今天有一个坑,同时要上传图片和文件,而且图片要展示缩略图,文件要展示列表. 我的思路是: 首先,只上传附件照片,这个直接看ele的官方例子就行,不仅仅上传附件照片,还同时上传其他参数. 然后,再做上传 ...

  7. python 全栈开发,Day129(玩具开机提示语,为多个玩具发送点播,聊天界面,app录音,app与服务器端文件传输,简单的对话)

    一.玩具开机提示语 先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.2.zi ...

  8. django的所有app放在一个文件夹下便于管理

    1.新建一个python Package,名字叫apps 2.拖拽以后的app到apps文件夹下,把Search for references勾选去掉,重要重要重要!!!! 3.右键点击apps文件夹 ...

  9. Facebook App 的头文件会有更多的收获

    最近在看一些 App 架构相关的文章,也看了 Facebook 分享的两个不同时期的架构(2013 和 2014),于是就想一窥 Facebook App 的头文件,看看会不会有更多的收获,确实有,还 ...

  10. ajax 提交所有表单内容及上传图片(文件),以及单独上传某个图片(文件)

    我以演示上传图片为例子: java代码如下(前端童鞋可以直接跳过看下面的html及js): package com.vatuu.web.action; import java.io.File; imp ...

随机推荐

  1. Kali 获取任意设备信息

    注意:仅供测试 请勿商用 可获取对方位置 误差小于500m 访问摄像头 访问麦克风 一. 安装环境 #01 mac 安装虚拟机 下载地址:https://www.macyy.cn/archives/1 ...

  2. [.Net]使用Soa库+Abp搭建微服务项目框架(三):项目改造

    ​上一章我们说道,如果要使各模块之间解耦,使得各自独立成服务,首先要解除各个模块之间的引用关系. 还记得上一章我们的小项目吗 ?们回到之前的代码上来,当前的项目架构如下图: ​ 这次的任务是将它改造成 ...

  3. vue配置scss全局样式

    安装插件 npm install sass --save-dev 在src文件夹下创建styles文件夹,并创建以下文件 index.scss: scss的入口文件 // 引入清除默认样式 @impo ...

  4. linux-给终端建立快捷键

    在设置里,找到快捷键窗口,自定义快捷键, 名字:终端 命令:gnome-terminal 快捷键:ctrl+alt+t

  5. labeImg 遇到闪退问题,TypeError: setValue(self, a0: int): argument 1 has unexpected type 'float'

    将python 环境安装为python3.9,然后重新安装labelImg

  6. 记一个很好用的轻量级翻译软件 copytranslator

    软件下载主页: https://gitee.com/ylzheng/CopyTranslator/wikis/windows 可以设置始终置顶,监听剪切板,翻译起来非常方便

  7. spring 整体框架介绍

    一.什么是Spring? 二.Spring能够解决什么问题? 三.Spring整体架构

  8. 企业家智能客服知识库重磅更新,发布`v0.1.5`

    FastWiki加入AIDotNet (github.com),FastWiki不再属于个人项目,目前FastWiki捐赠给了AIDotNet组织,AIDotNet拥有一下优秀项目: 项目名称 链接 ...

  9. ProtoBuf-gRPC实践

    目录介绍 01.gRPC学习背景 1.1 为什么要学RPC 1.2 RPC是什么 1.3 网络库收益分析 1.4 学习计划说明 1.5 学习问题思考 02.ProtoBuf的介绍 2.1 ProtoB ...

  10. torch的cuda版本安装

    1.拥有英伟达显卡NVIDIA NVIDIA CUDA各版本下载链接(包括最新11版本和以往10.2版本) 以下是从NVIDIA官网转过来的链接,方便需要下载各种版本CUDA的同学.(借阅) http ...