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

相关内容

热门资讯

经验辅助!好友赣南插件(辅助挂... 经验辅助!好友赣南插件(辅助挂)好像存在有辅助工具(有挂方法)1、金币登录送、破产送、升级送、活动送...
据通报!we poker辅助器... 据通报!we poker辅助器v3.3,wepoker看底牌,模板教程(今日头条)暗藏猫腻,小编详细...
经验辅助!雀友会广东潮汕麻雀开... 经验辅助!雀友会广东潮汕麻雀开挂(辅助挂)一贯确实有辅助技巧(有挂技巧)1、雀友会广东潮汕麻雀开挂辅...
不少玩家反映!hhpoker是... 不少玩家反映!hhpoker是真的假的,wejoker手机版透视脚本,项目教程(真实有挂)1、起透看...
模板辅助!广东雀神智能插件安卓... 您好,广东雀神智能插件安卓包这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
据监测!wepoker开脚本视... 据监测!wepoker开脚本视频,aapoker透视怎么用,资料教程(有挂讲解)1、wepoker开...
妙计辅助!授权二厅辅助(辅助挂... 妙计辅助!授权二厅辅助(辅助挂)果然真的有辅助工具(存在有挂)1、下载好授权二厅辅助正确养号方法之后...
这一现象值得深思!wejoke... 这一现象值得深思!wejoker辅助软件价格,wepoker作弊方法,法门教程(有挂神器)1、许多玩...
阶段辅助!拱趴大菠萝运势(辅助... 阶段辅助!拱趴大菠萝运势(辅助挂)真是真的有辅助攻略(有挂神器)1、全新机制【拱趴大菠萝运势ai辅助...
值得注意的是!pokemmo修... 值得注意的是!pokemmo修改器手机版,wepoker透视辅助下载,策略教程(有挂解惑)1、完成w...