美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联百度小程序教程:swan.cloud.uploadFile

  • swan.cloud.uploadFile

    swan.cloud.uploadFile

    解释:将本地资源上传至云存储空间,如果上传至相同路径则会进行资源覆盖。

    参数说明

    该方法的传入参数类型为对象类型,参数说明如下:

    字段 类型 必填 说明
    cloudPath String 云存储路径
    filePath String 要上传图片资源的路径
    config Object 局部覆盖 swan.cloud.init 中的全局配置
    success Function 接口调用成功的回调函数
    fail Function 接口调用失败的回调函数
    complete Function 接口调用结束的回调函数

    config说明:

    字段 类型 说明
    env String 使用的环境 ID,将覆盖swan.cloud.init指定的环境

    success返回参数说明

    字段 类型 说明
    fileID String 文件 ID
    statusCode Number 服务器返回的 HTTP 状态码
    errMsg String 调用成功的信息

    fail返回参数说明

    字段 类型 说明
    errCode Number 错误码
    errMsg String 错误信息

    代码示例
    callback风格:

    • JS
     
     
     
    1. swan.cloud.uploadFile({
    2. cloudPath,
    3. filePath,
    4. success: res => {
    5. console.log('[上传文件] 成功:' + res.fileID);
    6. },
    7. fail: e => {
    8. swan.showToast({
    9. icon: 'none',
    10. title: '上传失败'
    11. })
    12. },
    13. complete: () => {
    14. swan.hideLoading()
    15. }
    16. });

    Promise风格:

    • JS
     
     
     
    1. swan.cloud.uploadFile({
    2. cloudPath,
    3. filePath
    4. }).then(res => {
    5. console.log('[上传文件] 成功:' + res.fileID);
    6. }).catch(err => {
    7. swan.showToast({
    8. icon: 'none',
    9. title: '上传失败'
    10. })
    11. });

    网站标题:创新互联百度小程序教程:swan.cloud.uploadFile
    本文网址:http://www.zsjierui.cn/article/cohgppg.html

    其他资讯