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);                      }                 });                  }                  })                                }                            })

相关内容

热门资讯

3分钟神器!微扑克ai辅助器苹... 3分钟神器!微扑克ai辅助器苹果版(透明挂黑科技)外挂透明挂辅助智能(2021已更新)(哔哩哔哩);...
第2分钟领会!wepoker脚... 第2分钟领会!wepoker脚本,约局吧辅助器(透视)高科技教程(发现有挂)所有人都在同一条线上,像...
推荐攻略!wepoke透明挂辅... 推荐攻略!wepoke透明挂辅助,wepoke ai代打,必赢教程(有挂解密)-哔哩哔哩;人气非常高...
四分钟发现!wepokeai代... 四分钟发现!wepokeai代打辅助(透明挂黑科技)外挂透明挂辅助器(2024已更新)(哔哩哔哩);...
第8分钟发现!大菠萝789辅助... 第8分钟发现!大菠萝789辅助器下载,红龙poker透视挂指令(透视)透明教程(有挂攻略)1、上手简...
玩家必备教程!红龙扑克ai,w... 玩家必备教程!红龙扑克ai,wepoke用模拟器,玩家教程(有挂神器)-哔哩哔哩;wepoke用模拟...
6分钟私人局!wepoke智能... 6分钟私人局!wepoke智能ai什么意思(透明挂黑科技)外挂透明挂辅助神器(2026已更新)(哔哩...
第5分钟发现!hhpoker哪... 第5分钟发现!hhpoker哪个俱乐部靠谱,红龙poker有辅助吗(透视)wepoke教程(讲解有挂...
一分钟了解!wpk辅助实时策略... 一分钟了解!wpk辅助实时策略建议,德州之星外挂购买渠道,扑克教程(竟然有挂)-哔哩哔哩;1、超多福...
2分钟普及!aapoker发牌... 2分钟普及!aapoker发牌规律(透明挂黑科技)外挂透明挂辅助器(2023已更新)(哔哩哔哩);一...