简体中文
将本地资源上传到开发者服务器。
推荐上传到uniCloud,uniCloud提供了更便宜CDN和更好的易用性,详见
名称 | 类型 | 必填 | 默认值 | 描述 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | UploadFileOptions | 是 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Android | iOS | web | |
---|---|---|---|
name | 3.9 | 4.11 | - |
uri | 3.9 | 4.11 | - |
file | 3.9 | 4.11 | 4.0 |
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
data | string | 是 | - | 开发者服务器返回的数据 |
statusCode | number | 是 | - | 开发者服务器返回的 HTTP 状态码 |
Android | iOS | web | |
---|---|---|---|
data | 3.9 | 4.11 | - |
statusCode | 3.9 | 4.11 | - |
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
errCode | 5 | 1000 | 100001 | 100002 | 600003 | 600009 | 602001 | 是 | - | 错误码 - 5 接口超时 - 1000 服务端系统错误 - 100001 json数据解析错误 - 100002 错误信息json解析失败 - 600003 网络中断 - 600009 URL格式不合法 - 602001 request系统错误 |
errSubject | string | 是 | - | 统一错误主题(模块)名称 |
data | any | null | 否 | - | 错误信息中包含的数据 |
cause | Error | null | 否 | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - |
Android | iOS | web | |
---|---|---|---|
url | 3.9 | 4.11 | - |
filePath | 3.9 | 4.11 | - |
name | 3.9 | 4.11 | - |
files | 3.9 | 4.11 | - |
header | 3.9 | 4.11 | - |
formData | 3.9 | 4.11 | - |
timeout | 3.9 | 4.11 | - |
类型 |
---|
UploadTask |
中断上传任务。
Android | iOS | web |
---|---|---|
3.9 | 4.11 | 4.0 |
监听上传进度变化。
名称 | 类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
callback | (result: OnProgressUpdateResult) => void | 是 | - |
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
progress | number | 是 | - | 上传进度百分比 |
totalBytesSent | number | 是 | - | 已经上传的数据长度,单位 Bytes |
totalBytesExpectedToSend | number | 是 | - | 预期需要上传的数据总长度,单位 Bytes |
Android | iOS | web | |
---|---|---|---|
progress | 3.9 | 4.11 | - |
totalBytesSent | 3.9 | 4.11 | - |
totalBytesExpectedToSend | 3.9 | 4.11 | - |
Android | iOS | web |
---|---|---|
3.9 | 4.11 | 4.0 |
Android | iOS | web |
---|---|---|
3.9 | 4.11 | 4.0 |
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="demo">
<image v-if="imageSrc" :src="imageSrc" class="image" mode="widthFix"></image>
<text v-else class="uni-hello-addfile" @click="chooseImage">+ 选择图片</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<style>
.image {
width: 100%;
}
.demo {
background: #fff;
padding: 25px;
justify-content: center;
align-items: center;
}
.uni-hello-addfile {
text-align: center;
background: #fff;
padding: 25px;
margin-top: 10px;
font-size: 19px;
color: #808080;
}
</style>
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |
注意