All Products
Search
Document Center

File

Last Updated: Feb 04, 2021

my.saveFile

Note:
  • This interface is supported since basic library version 1.3.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to save the file to local. The maximum local file capacity is 10 MB. After my.saveFile is successfully called, you can find the saved files in the path storage/alipay/pictures/file location in Android device. Hidden file path in iOS device cannot be found.

Parameters

Parameter Type Required Description
apFilePath String Yes File path
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Return value on success

Parameter Type Description
apFilePath String File save path

Sample code

  1. my.chooseImage({
  2. success: (res) => {
  3. my.saveFile({
  4. apFilePath: res.apFilePaths[0],
  5. success: (res) => {
  6. console.log(JSON.stringify(res))
  7. },
  8. });
  9. },
  10. });

my.getFileInfo

Note:
  • This interface is supported since basic library version 1.4.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to get file information.

Parameters

Parameter Type Required Description
apFilePath String Yes File path (local path)
digestAlgorithm String No Digest algorithm, supporting md5 and sha1, md5 by default.
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Return value on success

Parameter Type Description
size Number File size
digest String Digest result.

Sample code

  1. my.getFileInfo({
  2. apFilePath:'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
  3. digestAlgorithm:'sha1',
  4. success:(res)=>{
  5. console.log(JSON.stringify(res))
  6. }
  7. })

my.getSavedFileInfo

Note:
  • This interface is supported since basic library version 1.3.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to get the information of the saved files.

Parameters

Parameter Type Required Description
apFilePath String Yes File path
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Return value on success

Parameter Type Description
size Number File size
createTime Number Creation time

Sample code

my.getSavedFileInfo only works on the file address saved by using my.saveFile.

  1. var that = this;
  2. my.chooseImage({
  3. success: (res) => {
  4. console.log(res.apFilePaths[0], 1212)
  5. my.saveFile({
  6. apFilePath: res.apFilePaths[0],
  7. success: (result) => {
  8. console.log(result, 1212)
  9. my.getSavedFileInfo({
  10. apFilePath: result.apFilePath,
  11. success: (resu) => {
  12. console.log(JSON.stringify(resu))
  13. that.filePath = resu
  14. }
  15. })
  16. },
  17. });
  18. },
  19. });

my.getSavedFileList

Note:
  • This interface is supported since basic library version 1.3.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to get all saved files.

Parameters

Parameter Type Required Description
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Return value on success

Parameter Type Description
fileList List File list

Attributes of file object

Attribute Type Description
size Number File size
createTime Number Creation time
apFilePath String File path

Sample code

  1. my.getSavedFileList({
  2. success:(res)=>{
  3. console.log(JSON.stringfy(res))
  4. }
  5. });

my.removeSavedFile

Note:
  • This interface is supported since basic library version 1.3.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to delete a saved file.

Parameters

Parameter Type Required Description
apFilePath String Yes File path
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Sample code

  1. my.getSavedFileList({
  2. success:(res)=>{
  3. my.removeSavedFile({
  4. apFilePath:res.fileList[0].apFilePath,
  5. success:(res)=>{
  6. console.log('remove success')
  7. }
  8. })
  9. }
  10. });