uniapp 新建文件

uniapp 新建文件 支持ios和android

function createFile(bases64, item, savedFilePathOne) {
// 请求文件系统
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
// let storageAddress = fs.root.toURL();
// 创建文件
fs.root.getFile( abc + '.txt', {
create: true
}, function(fileEntry) {
// 创建写入流
fileEntry.createWriter(function(writer) {
// 设置写入内容
writer.write('2222');
// writer.write(bases64);
// 写入完成回调
writer.onwriteend = function(res) {
console.log('写入文件成功', res.target.fileName);
/* uni.showModal({
title: '写入文件成功',
content: JSON.stringify(res.target.fileName),
showCancel: false
})*/
const pathUrl = res.target.fileName


if (pathUrl!= '') {
uni.saveFile({
tempFilePath: pathUrl,
success: function (resss) {
let savedFilePath = resss.savedFilePath;
}
});

}
};
// 写入错误回调
writer.onerror = function(err) {
console.error('写入文件失败', err);
};
},
function(err) {
console.error('创建写入流失败', err);
});
},
function(err) {
console.error('创建文件失败', err);
});
},
function(err) {
console.error('请求文件系统失败', err);
});
}

posted on 2024-05-08 18:49  完美前端  阅读(3)  评论(0编辑  收藏  举报

导航