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

相关内容

热门资讯

机巧辅助!wepoker插件辅... 机巧辅助!wepoker插件辅助(辅助)确实是有辅助教程(有挂总结)1、完成wepoker插件辅助辅...
烘培辅助!aapoker安装包... 烘培辅助!aapoker安装包怎么使用(辅助)总是是有辅助神器(有挂猫腻)1、任何aapoker安装...
要领辅助!wepoker透视有... 要领辅助!wepoker透视有吗(辅助)切实是真的有辅助技巧(揭秘有挂)wepoker透视有吗能透视...
讲义辅助!aapoker辅助工... 讲义辅助!aapoker辅助工具安全吗(辅助)好像是有辅助方法(竟然有挂)该软件可以轻松地帮助玩家将...
绝活儿辅助!竞技联盟辅助插件(... 绝活儿辅助!竞技联盟辅助插件(辅助)确实存在有辅助工具(有挂分析)竞技联盟辅助插件破解侠是真的助透视...
指南书辅助!wepoker好友... 指南书辅助!wepoker好友房开挂(辅助)都是有辅助器(讲解有挂)wepoker好友房开挂能透视中...
窍要辅助!wepoker手机版... 窍要辅助!wepoker手机版辅助(辅助)一贯是有辅助神器(今日头条)1、该软件可以轻松地帮助玩家将...
秘籍辅助!德普之星辅助工具如何... 秘籍辅助!德普之星辅助工具如何打开(辅助)真是是有辅助攻略(揭秘有挂)1)德普之星辅助工具如何打开免...
诀窍辅助!wepoker免费脚... 诀窍辅助!wepoker免费脚本(辅助)原来有辅助脚本(有挂方针)1、wepoker免费脚本透视辅助...
步骤辅助!竞技联盟透视插件(辅... 步骤辅助!竞技联盟透视插件(辅助)一贯真的是有辅助app(详细教程)1、全新机制【竞技联盟透视插件a...