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

参考文档

类型

  1. (option: Option) => Promise<SuccessCallbackResult | FailCallbackResult>

参数

Option

参数类型必填说明
tempFilePathstring临时存储文件路径
complete(res: CallbackResult) => void接口调用结束的回调函数(调用成功、失败都会执行)
fail(result: FailCallbackResult) => void接口调用失败的回调函数
filePathstring要存储的文件路径
success(result: SuccessCallbackResult) => void接口调用成功的回调函数

FailCallbackResult

参数类型说明
errMsgstring错误信息

可选值:
- ‘fail tempFilePath file not exist’: 指定的 tempFilePath 找不到文件;
- ‘fail permission denied, open “filePath”‘: 指定的 filePath 路径没有写权限;
- ‘fail no such file or directory “dirPath”‘: 上级目录不存在;
- ‘fail the maximum size of the file storage limit is exceeded’: 存储空间不足;

SuccessCallbackResult

参数类型说明
savedFilePathnumber存储后的文件路径
errMsgstring调用结果

示例代码

  1. Taro.chooseImage({
  2. success: function (res) {
  3. var tempFilePaths = res.tempFilePaths
  4. Taro.saveFile({
  5. tempFilePath: tempFilePaths[0],
  6. success: function (res) {
  7. var savedFilePath = res.savedFilePath
  8. }
  9. })
  10. }
  11. })

API 支持度

API微信小程序H5React Native
Taro.saveFile✔️