uniapp如何修改下载文件位置

1、根据下载的方法,请见:下载的方法下载的方法

2、修改下载文件的位置

复制代码
const fileWriter = () => {
  // 请求本地系统文件对象 plus.io.PRIVATE_WWW:应用运行资源目录常量
  plus.io.requestFileSystem(plus.io.PRIVATE_DOC, (fobject) => {
    // fs.root是根目录操作对象DirectoryEntry
    const fileName = formatTime(new Date()) + '.txt'; // 文件名
    fobject.root.getFile(fileName, {
      create: true
    }, (fileEntry) => {
      fileEntry.file((file) => {
        console.log('file :>> ', file)
        // create a FileWriter to write to the file
        fileEntry.createWriter((writer) => {
          console.log('writer :>> ', writer)
          // 返回页面的数据
          writer.seek(file.size)
          // 写入可以加入需要写入的数据
          let content = "{points:" + JSON.stringify(polyline.value[0].points) + ",pointArr:" + JSON.stringify(pointArr.value)+ "}"
          writer.write(content)
          const fileReader = new plus.io.FileReader()
          fileReader.readAsText(file, 'utf-8')
          // 获取对象 
          plus.io.resolveLocalFileSystemURL(file.fullPath, (res) => {
            // 获取公共下载目录
            plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, (downloadFs) => {
              console.log('downloadFs :>> ', downloadFs)
              // 移动文件到下载目录(若需复制则用 copyTo)
              fileEntry.copyTo(downloadFs.root, fileName, (newFileEntry) => {
                console.log('文件已移动到下载目录:', newFileEntry.fullPath);
                
                // 7. 打开文件
                uni.openDocument({
                  filePath: newFileEntry.fullPath,
                  success: () => console.log('文件打开成功'),
                  fail: (err) => console.error('打开文件失败:', err)
                });
              }, (err) => {
                console.error('移动文件失败:', err);
              });
            });
            
          })
        }, (e) => {
          console.log('e :>> ', e)
        })
      })
    })
  })
}
相关推荐
我命由我12345几秒前
Jetpack Room - Room 查询返回列表无需判空、LIKE 关键字
android·java·开发语言·java-ee·android jetpack·android-studio·android runtime
#麻辣小龙虾#10 分钟前
vue3基于leaflet.js实现地图编辑功能
javascript·ecmascript·leaflet.js
goodluckyaa10 分钟前
Warp shuffle函数
开发语言
j7~12 分钟前
【C++】STL--Vector容器--拆析解剖Vector的实现以及Vector的底层详解(1)
开发语言·c++·vector·迭代器失效·迭代器的使用
AHRIKNOW14 分钟前
写一个 Fetch 封装库,没那么简单
javascript
奇奇怪怪的17 分钟前
浏览器线程与进程深度剖析
前端
xxwl58517 分钟前
Python语言初步认识(1)
开发语言·python·学习
渣波17 分钟前
手把手教你写出优雅的 API 接口调用
前端·javascript
YHL18 分钟前
🧊 CSS 3D 硬核解析:四个属性手写旋转立方体
前端·css·html
spmcor18 分钟前
JavaScript 日期限制的“三个月陷阱”:从边界溢出到稳健实现
javascript