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辅助!wepoker透视... 阶段f辅助!wepoker透视方法,hhpoker德州有挂吗,解密教程(有挂工具)hhpoker德州...
诀窍f辅助!hhpoker德州... 诀窍f辅助!hhpoker德州作弊,wejoker手机版透视脚本,关于教程(讲解有挂)1、首先打开w...
教材f辅助!werplan怎么... 教材f辅助!werplan怎么透视,悟空黑桃a有挂嘛,解密教程(讲解有挂)1、悟空黑桃a有挂嘛公共底...
诀窍f辅助!如何下载wepok... 诀窍f辅助!如何下载wepoker安装包,hhpoker德州真的假的,分享教程(有挂透视)如何下载w...
总结f辅助!wepoker辅助... 总结f辅助!wepoker辅助器怎么弄,pokernow辅助工具,推荐教程(确实有挂)进入游戏-大厅...
要领f辅助!约局吧游戏挂,xp... 要领f辅助!约局吧游戏挂,xpoker怎么作弊,辅助教程(真实有挂)1、进入到约局吧游戏挂是否有挂之...
总结f辅助!德州私人局脚本,a... 总结f辅助!德州私人局脚本,aapoker破解侠是真的吗,关于教程(有挂解密)1、上手简单,内置详细...
绝活f辅助!wepoker轻量... 绝活f辅助!wepoker轻量版辅助,hhpoker透视工具,解迷教程(有挂猫腻)一、wepoker...
大纲f辅助!拱趴大菠萝挂哪里,... 大纲f辅助!拱趴大菠萝挂哪里,wepoker线上大神,普及教程(有挂存在)1、在拱趴大菠萝挂哪里插件...
技法f辅助!哈糖大菠萝能开挂吗... 技法f辅助!哈糖大菠萝能开挂吗,hhpoker德州机器人,曝光教程(有挂分析)1、上手简单,内置详细...