收藏
回答

小程序如何删除保存的文件?

uni.downloadFile({
                    url: downloadUrl,
                    filePath: tempFilePath,
                    success: (res) => {
                        console.log('====download', res);
                        resolve(res)
                    },
                    fail: (err) => reject(err)
                });

删除逻辑代码

wx.getFileSystemManager().saveFile({
            tempFilePath: path,
            success(res) {
                wx.getFileSystemManager().removeSavedFile({
                    filePath: res.savedFilePath,
                    success: (delRes) => {
                        console.log("删除文件成功:", delRes);
                    },
                    fail: (delErr) => {
                        console.log("删除文件出错:", res, delErr);
                    },
                })
            },
            fail(err) {
                console.log("保存文件出错:", err);
            },
        })

uni.getSavedFileList({
            success: function (res) {
                console.log('文件列表', res);
                if (res.fileList.length > 0) {
                    uni.removeSavedFile({
                        filePath: res.fileList[0].filePath,
                        complete: function (res) {
                            console.log(res);
                        }
                    });
                }
            }
        });


日志截图和文件列表截图


回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    2025-09-16
    有用
    回复
登录 后发表内容