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

相关内容

热门资讯

大纲f辅助!wpk俱乐部有没有... 大纲f辅助!wpk俱乐部有没有辅助,wepoker祈福有用吗,必备教程(有挂详情)1、该软件可以轻松...
方针f辅助!红龙poker辅助... 方针f辅助!红龙poker辅助器免费观看,wepoker插件下载,解迷教程(有人有挂)1、许多玩家不...
手册f辅助!大菠萝789辅助器... 手册f辅助!大菠萝789辅助器下载,wepoker破解器,专业教程(有挂细节)1、每一步都需要思考,...
策略f辅助!wepoker怎么... 策略f辅助!wepoker怎么拿到好牌,aapoker透视插件,详细教程(有挂攻略)1)wepoke...
法子f辅助!wepoker辅助... 法子f辅助!wepoker辅助器激活码,聚星ai辅助工具下载,详细教程(竟然有挂)1、玩家可以在聚星...
手筋f辅助!xpoker怎么作... 手筋f辅助!xpoker怎么作弊,wejoker手机版透视脚本,详情教程(有挂方针)1、wejoke...
讲义f辅助!wepokerpl... 讲义f辅助!wepokerplus开挂,wepoker辅助工具,普及教程(揭秘有挂)1、不需要AI权...
学习f辅助!pokemomo辅... 学习f辅助!pokemomo辅助软件,newpoker脚本,分享教程(真的有挂)1、每一步都需要思考...
经验f辅助!aapoker辅助... 经验f辅助!aapoker辅助工具安全吗,sohoopoker辅助,有挂教程(有挂解密)暗藏猫腻,小...
模块f辅助!wepoker怎么... 模块f辅助!wepoker怎么挂飞机,hhpkoer辅助器视频,有挂教程(发现有挂)1、实时hhpk...