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.
Type
(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
Taro.chooseImage({
success: function (res) {
var tempFilePaths = res.tempFilePaths
Taro.saveFile({
tempFilePath: tempFilePaths[0],
success: function (res) {
var savedFilePath = res.savedFilePath
}
})
}
})
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.saveFile | ✔️ | ✔️ |