title: Taro.saveFile(option)

sidebar_label: saveFile

Saves files to the local device. Note: saveFile will move temporary files, so tempFilePath will not be available after the API is successfully called.

Reference

Type

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

Parameters

Option

Property Type Required Description
tempFilePath string Yes Temporary path to the files to be saved
filePath string No Path of the file to be saved
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

FailCallbackResult

Property Type Description
errMsg string Error message

valid value:
- ‘fail tempFilePath file not exist’;
- ‘fail permission denied, open "filePath"’;
- ‘fail no such file or directory "dirPath"’;
- ‘fail the maximum size of the file storage limit is exceeded’;

SuccessCallbackResult

Property Type Description
savedFilePath number Path to the saved file
errMsg string Call result

Sample Code

  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 Support

API WeChat Mini-Program H5 React Native
Taro.saveFile ✔️ ✔️