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辅助!hhpoker是真... 指引f辅助!hhpoker是真的假的,wepoker辅助透视,解密教程(有挂技术)hhpoker是真...
机巧f辅助!红龙poker辅助... 机巧f辅助!红龙poker辅助工具,红龙poker辅助工具,推荐教程(的确有挂)一、红龙poker辅...
绝活f辅助!htx矩阵wepo... 绝活f辅助!htx矩阵wepoker辅助,wepoker脚本,揭幕教程(有挂秘笈)1、htx矩阵we...
经验f辅助!wepoker辅助... 经验f辅助!wepoker辅助器,wepoker私人局透视,必备教程(有挂规律);1、上手简单,内置...
办法f辅助!wepoker怎么... 办法f辅助!wepoker怎么发冤家牌,wpk作弊最怕三个东西,教你教程(有挂助手)1、操作简单,无...
积累f辅助!德普之星透视软件免... 积累f辅助!德普之星透视软件免费入口官网,wepoker私人局规律,普及教程(有挂技术)1、许多玩家...
窍要f辅助!wpk有那种辅助吗... 窍要f辅助!wpk有那种辅助吗,德州局透视,教你教程(揭秘有挂)1)wpk有那种辅助吗辅助插件:进一...
指引f辅助!poker mas... 指引f辅助!poker master辅助,德州私人局脚本,解密教程(有挂攻略);1、德州私人局脚本脚...
学习f辅助!wejoker辅助... 学习f辅助!wejoker辅助机器人,wepoker有没有机器人,专业教程(有挂解惑)1、很好的工具...
演示f辅助!aa poker辅... 演示f辅助!aa poker辅助,佛手大菠萝有挂吗,分享教程(真的有挂)1、佛手大菠萝有挂吗免费辅助...