Skip to main content
Version: Next

Taro.saveFile(option)

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

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

Parameters

Option

PropertyTypeRequiredDescription
tempFilePathstringYesTemporary path to the files to be saved
filePathstringNoPath of the file to be saved
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

FailCallbackResult

PropertyTypeDescription
errMsgstringError 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

PropertyTypeDescription
savedFilePathnumberPath to the saved file
errMsgstringCall result

Sample Code

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

API Support

APIWeChat Mini-ProgramH5React Native
Taro.saveFile✔️✔️