文档

文件

更新时间:

my.saveFile

说明

基础库 1.13.0 及以上版本支持该接口,低版本需做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。

该接口用于保存文件到本地(本地文件大小总容量限制:10M)。调用 my.saveFile 成功后,安卓系统可在手机存储/alipay/pictures/文件位置查看保存的文件;iOS 系统无法查看被隐藏的目录路径。

入参

名称

类型

必填

描述

apFilePath

String

文件路径

success

Function

调用成功的回调函数

fail

Function

调用失败的回调函数

complete

Function

调用结束的回调函数(调用成功、失败都会执行)

success 返回值说明

名称

类型

描述

apFilePath

String

文件保存路径

代码示例

my.chooseImage({
  success: (res) => {
    my.saveFile({
      apFilePath: res.apFilePaths[0],
      success: (res) => {
        console.log(JSON.stringify(res))
      },
    });
  },
});

my.getFileInfo

说明

基础库 1.4.0 及以上版本支持该接口,低版本需做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。

入参说明

名称

类型

必填

描述

apFilePath

String

文件路径(本地路径)

digestAlgorithm

String

摘要算法,支持 md5sha1 ,默认为 md5

success

Function

调用成功的回调函数

fail

Function

调用失败的回调函数

complete

Function

调用结束的回调函数(调用成功、失败都会执行)

success 返回值说明

名称

类型

描述

size

Number

文件大小

digest

String

摘要结果

代码示例

my.getFileInfo({
    apFilePath:'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
    digestAlgorithm:'sha1',
    success:(res)=>{
        console.log(JSON.stringify(res))
    }
})

my.getSavedFileInfo

说明

基础库 1.3.0 及以上版本支持该接口,低版本需做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。

该接口用于获取保存的文件信息。

入参

名称

类型

必填

描述

apFilePath

String

文件路径

success

Function

调用成功的回调函数

fail

Function

调用失败的回调函数

complete

Function

调用结束的回调函数(调用成功、失败都会执行)

success 返回值说明

名称

类型

描述

size

Number

文件大小

createTime

Number

创建时间的时间戳

代码示例

使用 my.saveFile 保存的地址才能够使用 my.getSavedFileInfo

var that = this;
    my.chooseImage({
    success: (res) => {
      console.log(res.apFilePaths[0], 1212)
      my.saveFile({
        apFilePath: res.apFilePaths[0],
        success: (result) => {
          console.log(result, 1212)
          my.getSavedFileInfo({
            apFilePath: result.apFilePath,
            success: (resu) => {
              console.log(JSON.stringify(resu))
              that.filePath = resu
            }
          })
        },
      });
    },
});

my.getSavedFileList

说明

基础库 1.13.0 及以上版本支持该接口,低版本需做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。

该接口用于获取保存的所有文件。

入参

名称

类型

必填

描述

success

Function

调用成功的回调函数

fail

Function

调用失败的回调函数

complete

Function

调用结束的回调函数(调用成功、失败都会执行)

success 返回值说明

名称

类型

描述

fileList

List

文件列表

File 对象属性说明

名称

类型

描述

size

Number

文件大小

createTime

Number

创建时间

apFilePath

String

文件路径

代码示例

my.getSavedFileList({
    success:(res)=>{
        console.log(JSON.stringfy(res))
    }
});

my.removeSavedFile

说明

基础库 1.13.0 及以上版本支持该接口,低版本需做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。

该接口用于将删除某个保存的文件。

入参

名称

类型

必填

描述

apFilePath

String

文件路径

success

Function

调用成功的回调函数

fail

Function

调用失败的回调函数

complete

Function

调用结束的回调函数(调用成功、失败都会执行)

代码示例

my.getSavedFileList({
        success:(res)=>{
            my.removeSavedFile({
          apFilePath:res.fileList[0].apFilePath,
          success:(res)=>{
            console.log('remove success')
          }
        })
        }
    });
  • 本页导读 (0)
文档反馈