Skip to content

qin.saveFile(OBJECT) ​

保存文件到本地。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√x√√√√√x√

注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用

微信小程序已停止维护 wx.saveFile(Object)接口,建议使用FileSystemManager对象中的方法。

OBJECT 参数说明:

参数名类型必填说明
tempFilePathString是需要保存的文件的临时路径
successFunction否返回文件的保存路径,res =
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明:

参数说明
savedFilePath文件的保存路径

示例代码:

js
qin.chooseImage({
  success: function (res) {
    var tempFilePaths = res.tempFilePaths;
    qin.saveFile({
      tempFilePath: tempFilePaths[0],
      success: function (res) {
        var savedFilePath = res.savedFilePath;
      }
    });
  }
});
qin.chooseImage({
  success: function (res) {
    var tempFilePaths = res.tempFilePaths;
    qin.saveFile({
      tempFilePath: tempFilePaths[0],
      success: function (res) {
        var savedFilePath = res.savedFilePath;
      }
    });
  }
});

qin.getSavedFileList(OBJECT) ​

获取本地已保存的文件列表。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√x√√√√√x√

微信小程序已停止维护wx.getSavedFileList(Object object)接口,建议使用FileSystemManager对象中的方法。

OBJECT 参数说明:

参数名类型必填说明
successFunction否接口调用成功的回调函数,返回结果见 success 返回参数说明
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明:

参数类型说明
errMsgString接口调用结果
fileListArray<Object>文件列表

fileList 中的项目说明:

键类型说明
filePathString文件的本地路径
createTimeNumber文件的保存时的时间戳,从 1970/01/01 08:00:00 到该时刻的秒数。
sizeNumber文件大小,以字节为单位。

示例代码:

js
qin.getSavedFileList({
  success: function (res) {
    console.log(res.fileList);
  }
});
qin.getSavedFileList({
  success: function (res) {
    console.log(res.fileList);
  }
});

qin.getSavedFileInfo(OBJECT) ​

获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√x√√√x√x√

微信小程序已停止维护wx.getSavedFileInfo(Object object)接口,建议使用FileSystemManager对象中的方法。

OBJECT 参数说明:

参数名类型必填说明
filePathString是文件路径
successFunction否接口调用成功的回调函数,返回结果见 success 返回参数说明
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明:

参数类型说明
errMsgString接口调用结果
sizeNumber文件大小,以字节为单位。
createTimeNumber文件保存时的时间戳,从 1970/01/01 08:00:00 到该时刻的秒数。

示例代码:

js
qin.getSavedFileInfo({
  filePath: 'unifile://somefile', //仅做示例用,非真正的文件路径
  success: function (res) {
    console.log(res.size);
    console.log(res.createTime);
  }
});
qin.getSavedFileInfo({
  filePath: 'unifile://somefile', //仅做示例用,非真正的文件路径
  success: function (res) {
    console.log(res.size);
    console.log(res.createTime);
  }
});

qin.removeSavedFile(OBJECT) ​

删除本地存储的文件。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√x√√√√√x√

微信小程序已停止维护wx.removeSavedFile(Object object)接口,建议使用FileSystemManager对象中的方法。

OBJECT 参数说明:

参数名类型必填说明
filePathString是需要删除的文件路径
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

js
qin.getSavedFileList({
  success: function (res) {
    if (res.fileList.length > 0) {
      qin.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete: function (res) {
          console.log(res);
        }
      });
    }
  }
});
qin.getSavedFileList({
  success: function (res) {
    if (res.fileList.length > 0) {
      qin.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete: function (res) {
          console.log(res);
        }
      });
    }
  }
});

qin.getFileInfo(OBJECT) ​

获取文件信息

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√√√√√√√x√

微信小程序已停止维护wx.getFileInfo(Object object)接口,建议使用FileSystemManager对象中的方法。

OBJECT 参数说明:

参数名类型默认值必填说明平台差异说明
filePathString是本地文件路径
digestAlgorithmStringmd5否计算文件摘要的算法,可取值 md5、sha1。微信小程序、京东小程序、App 2.9.0+
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行) 

success 返回参数说明:

参数类型说明平台差异说明
errMsgString接口调用结果
sizeNumber文件大小,以字节为单位。
digestString按照传入的 digestAlgorithm 计算得出的的文件摘要微信小程序、京东小程序、App 2.9.0+

qin.openDocument(OBJECT) ​

新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。

平台差异说明

AppH5微信小程序支付宝小程序百度小程序抖音小程序、飞书小程序QQ小程序快手小程序京东小程序
√x√√√√√x√

OBJECT 参数说明:

参数名类型必填说明平台差异说明
filePathString是文件路径,可通过 downFile 获得
fileTypeString支付宝小程序必填,其他平台非必填文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx,支付宝小程序仅支持pdf微信小程序、支付宝小程序、京东小程序
showMenuBoolean否右上角是否有可以转发分享的功能微信小程序
successString否接口调用成功的回调函数
failString否接口调用失败的回调函数微信小程序、京东小程序
completeString否接口调用结束的回调函数(调用成功、失败都会执行) 

示例代码:

js
qin.downloadFile({
  url: 'https://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath;
    qin.openDocument({
      filePath: filePath,
      showMenu: true,
      success: function (res) {
        console.log('打开文档成功');
      }
    });
  }
});
qin.downloadFile({
  url: 'https://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath;
    qin.openDocument({
      filePath: filePath,
      showMenu: true,
      success: function (res) {
        console.log('打开文档成功');
      }
    });
  }
});

平台差异

平台打开方式
小程序在小程序的入口应用内打开
App iOS在当前应用内打开
App Android调用系统相关应用打开,无相关应用则不能打开
H5使用浏览器打开,当前浏览器不支持则不能打开

Tips