export default class Main {
constructor() {
this.testFile(this);
}
testFile(mainobj) {
var downloadTask = wx.downloadFile({
url: "https://res.wx.qq.com/a/wx_fed/weixin_portal/res/static/img/dNEBuK6.png",
success: function (res) {
if (res.statusCode === 200) {
var fsm = wx.getFileSystemManager();
fsm.saveFile(
{
tempFilePath: res.tempFilePath,
filePath: wx.env.USER_DATA_PATH + "/a.png",
success: function (res) {
console.log("保存文件成功:"+res.savedFilePath);
mainobj.testgetSavedFileList();
mainobj.testAccessSync(res.savedFilePath);
mainobj.testremoveSavedFile(res.savedFilePath);
}
}
);
} else {
console.log("download url error,status:" + res.statusCode);
console.log("download url:" + url);
}
},
fail: function (res) {
console.log(res);
}
});
}
testgetSavedFileList() {
wx.getFileSystemManager().getSavedFileList(
{
"success": function (res) {
console.log("getSavedFileList() 测试:");
console.log(res);
},
"fail": function (res) {
console.log(res);
}
}
);
}
testAccessSync(path) {
var exist = false;
try {
wx.getFileSystemManager().accessSync(path);
exist = true;
} catch (e) {
exist = false;
}
console.log("accessSync() 测试是否存在:" + exist);
}
testremoveSavedFile(path) {
wx.getFileSystemManager().removeSavedFile(
{
"filePath":path,
"success": function (res) {
console.log("removeSavedFile() success:");
console.log(res);
},
"fail": function (res) {
console.log("removeSavedFile() fail:");
console.log(res);
}
}
);
}
testunlink(path) {
wx.getFileSystemManager().unlinkSync(path);
console.log("unlink删除");
}
}
|