# uploadFile(options)

上传文件到云存储

# 参数

名称 类型 必填 默认值 描述
options UniCloudUploadFileOptions - -
名称 类型 必备 默认值 描述
filePath string - 文件路径
cloudPath string - 云端路径
cloudPathAsRealPath boolean - 是否以云端路径是否为真实路径保存上传的文件

# UniCloudUploadFileOptions 的方法

# onUploadProgress(options)

上传进度回调

# 参数
名称 类型 必填 默认值 描述
options UniCloudUploadProgress - 上传进度回调参数
名称 类型 必备 默认值 描述
loaded number - 已上传大小
total number - 总大小
# 返回值
类型
any

# 返回值

类型
Promise<UniCloudUploadFileResult>
名称 类型 必备 默认值 描述
filePath string - 文件路径
fileID string - 文件id

# uploadFile 兼容性

Android iOS web
阿里云 3.9,腾讯云 3.91,支付宝云 3.98 4.11 4.0

# 参见

相关 Bug

# chooseAndUploadFile(options)

选择并上传文件

# 参数

名称 类型 必填 默认值 描述
options UniCloudChooseAndUploadFileOptions - -
名称 类型 必备 默认值 描述
sourceType Array<string> | null -
count number | null -
sizeType Array<string> | null -
extension Array<string> | null -
compressed boolean | null -
maxDuration number | null -
camera string | null -
crop ChooseImageCropOptions | null -
type string - -

# UniCloudChooseAndUploadFileOptions 的方法

# onChooseFile(arg)

# 参数
名称 类型 必填 默认值 描述
arg UniCloudChooseFileResult - -
名称 类型 必备 默认值 描述
tempFiles Array<UniCloudChooseFileItem> - -
名称 类型 必备 默认值 描述
name string - -
path string - -
cloudPath string - -
cloudPathAsRealPath boolean | null -
url string | null -
errMsg string | null -
tempFilePaths Array<string> - -
# 返回值
类型 必备
void | null

# onUploadProgress(arg)

# 参数
名称 类型 必填 默认值 描述
arg UniCloudChooseAndUploadFileProgressEvent - -
名称 类型 必备 默认值 描述
index number - -
loaded number - -
total number - -
tempFilePath string - -
tempFile UniCloudChooseFileItem - -
# 返回值
类型 必备
void | null

# 返回值

类型
Promise<UniCloudChooseAndUploadFileResult>
名称 类型 必备 默认值 描述
tempFiles Array<UniCloudChooseFileItem> - -
名称 类型 必备 默认值 描述
name string - -
path string - -
cloudPath string - -
cloudPathAsRealPath boolean | null -
url string | null -
errMsg string | null -
tempFilePaths Array<string> - -

# chooseAndUploadFile 兼容性

Android iOS web
阿里云 3.9,腾讯云 3.91,支付宝云 3.98 4.11 4.0

# 参见

相关 Bug

注意

  • 由于uni-app-x暂不支持选择视频、文件,目前此接口仅能上传图片,即type参数仅能设为image

# getTempFileURL(options)

获取文件临时URL

# 参数

名称 类型 必填 默认值 描述
options UniCloudGetTempFileURLOptions - -
名称 类型 必备 默认值 描述
fileList Array<string> - 文件列表

# 返回值

类型
Promise<UniCloudGetTempFileURLResult>
名称 类型 必备 默认值 描述
fileList Array<UniCloudGetTempFileURLResultItem> - 文件列表
名称 类型 必备 默认值 描述
fileID string - 文件id
tempFileURL string - 文件临时url

# getTempFileURL 兼容性

Android iOS web
阿里云 3.9,腾讯云 3.91,支付宝云 3.98 4.11 4.0

# 参见

相关 Bug

# 示例

hello uni-app x

Template

Script

<template>
  <!-- #ifdef APP -->
  <scroll-view class="page-scroll-view">
  <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-padding-wrap uni-common-mt">
        <view class="uni-btn-v uni-common-mt">
          <button type="primary" @click="uploadFile">选择文件上传</button>
        </view>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>


<style>
</style>