HomeDocs
Skip to main content

FileSystemManager.saveFile

Introduction

Save temporary files locally. This interface will move the temporary file, so after a successful call, the tempFilePath will no longer be available. You can only save from a temporary file to a local storage file.

Usage Limitations

Supported in the base library version 3.0.0 or higher.

Parameters

Object object

AttributeTypeDefaultRequiredDescription
tempFilePathstringYesTemporary storage file path (relative path)
filePathstringYesPath to store the file (relative path)
successfunctionNoCallback function for a successful API call
failfunctionNoCallback function for a failed API call
completefunctionNoCallback function for the end of the API call (executed for both successful and failed calls)

object.success

Callback Function

Parameters

Object res

AttributeTypeDescription
savedFilePathstringFile path after successful storage (relative path)
successstringtrue-Set successfully

object.fail Callback Function

Parameters

Object res

AttributeTypeDescription
errMsgstringError message
successstringfalse-Set failed

errMsg Description

Error MessageDescription
parameter error: F10001The original path or destination path parameter is null
fail sdcard not mounted: F10002Android sdcard mount failed
fail the maximum size of the file storage limit exceeded: F10004Insufficient storage space
fail permission denied: F10005, open "${filePath}"No write permission for the specified filePath path
fail no such file or directory: F10007 "${filePath}"Parent directory does not exist
fail tempFilePath file not existThe specified tempFilePath file cannot be found

Sample Code

// pages/index/index.js
Page({
saveFile() {
const fs = dlt.getFileSystemManager();
fs.saveFile({
tempFilePath: 'xxx.png',
filePath: `${dlt.env.USER_DATA_PATH}/hello.png`,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.