uniapp中临时文件路径上传后端服务器
创始人
2025-01-17 01:03:30
0

1.临时文件转base64

 uni.getFileSystemManager().readFile({ 							   filePath:e.detail.avatarUrl, 							   encoding:'base64', 							   success:r => { 								   console.log(r.data,'base64'); 							   } 						   })

2.base64转本地文件路径

const fileName = 'test.jpg'; // 指定文件名  const filePath =`${wx.env.USER_DATA_PATH}/${fileName}`; // 拼接文件路径  uni.getFileSystemManager().writeFile({ 				 filePath, 				 data: r.data,//上面的base64 				 encoding: 'base64', 				 success() { 				 console.log('写入文件成功', filePath);///zb_users/upload/2024/csdn/test.jpg                  }                  })

3.上传文件

uni.uploadFile({             url: 'xxx', // 替换成你的上传接口地址             filePath, // 传入本地文件路径             name: 'file', // 服务器接收的文件字段名 			success(uploadFileRes) { 					let data = JSON.parse(uploadFileRes.data) 					console.log(data,'uploadFileRes'); 									}, 		    fail(err) { 					console.error('上传失败', err); 					 } 				});

 4.整体

 uni.getFileSystemManager().readFile({                                filePath:e.detail.avatarUrl,                                encoding:'base64',                                success:r => {                                    console.log(r.data,'base64');                  const fileName = 'test.jpg'; // 指定文件名                  const filePath =`${wx.env.USER_DATA_PATH}/${fileName}`; // 拼接文件路径  uni.getFileSystemManager().writeFile({                  filePath,                  data: r.data,//上面的base64                  encoding: 'base64',                  success() {                  console.log('写入文件成功', filePath);///zb_users/upload/2024/csdn/test.jpg  uni.uploadFile({             url: 'xxx', // 替换成你的上传接口地址             filePath, // 传入本地文件路径             name: 'file', // 服务器接收的文件字段名             success(uploadFileRes) {                     let data = JSON.parse(uploadFileRes.data)                     console.log(data,'uploadFileRes');                                     },             fail(err) {                     console.error('上传失败', err);                      }                 });                  }                  })                                }                            })

相关内容

热门资讯

必备攻略!微信微乐游戏辅助器-... 必备攻略!微信微乐游戏辅助器-是真的有外挂(辅助)app(有挂辅助)是一款可以让一直输的玩家,快速成...
揭秘一下!边锋干瞪眼ios辅助... 揭秘一下!边锋干瞪眼ios辅助微信(了解辅助插件)原来有透视手段揭秘一下!边锋干瞪眼ios辅助微信(...
2分钟辅助!pokemomo辅... 2分钟辅助!pokemomo辅助软件,wpk插件,详细教程(真实有挂)1、在pokemomo辅助软件...
一起来探讨!陕西扣点点脚本辅助... 《一起来探讨!陕西扣点点脚本辅助器-是真的有外挂(辅助)下载(有挂讲解)》 陕西扣点点脚本辅助器软件...
必备攻略!乐玩游戏辅助工具(辅... 必备攻略!乐玩游戏辅助工具(辅助辅助器)真是有透视模块1、完成乐玩游戏辅助工具有辅助插件,帮助玩家取...
1分钟辅助!wepoker透视... 1分钟辅助!wepoker透视功能下载,wepoker国外版透视,详细教程(有挂存在)1、很好的工具...
终于知道!789大菠萝攻略-有... 终于知道!789大菠萝攻略-有外挂(辅助)神器(有挂功能);789大菠萝攻略是一种具有地方特色的麻将...
2分钟细说!鸿狐拼十辅助(详情... 2分钟细说!鸿狐拼十辅助(详情辅助神器)竟然有透视教材该软件可以轻松地帮助玩家将鸿狐拼十辅助外卦神器...
第1分钟辅助!hhpoker作... 第1分钟辅助!hhpoker作弊码怎么用,wpk辅助软件,详细教程(有挂教程)1、实时hhpoker...
盘点几款!wepoker怎么买... 您好,wepoker怎么买辅助这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...