Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uploadFile): fix Taro.uploadFile() #1115

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/taro-alipay/src/native-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,16 @@ function processApis (taro) {
})
if (newKey === 'uploadFile' || newKey === 'downloadFile') {
p.progress = cb => {
task.onProgressUpdate(cb)
if (task) {
task.onProgressUpdate(cb)
}
return p
}
p.abort = cb => {
cb && cb()
task.abort()
if (task) {
task.abort()
}
return p
}
}
Expand Down
27 changes: 26 additions & 1 deletion packages/taro-h5/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ declare namespace TaroH5 {
*/
statusCode: number
}
/**
* 上传进度
*/
type UploadTaskProgress = {
progress: number
totalBytesSent: number
totalBytesExpectedToSend: number
}
/**
* 上传进度回调
*/
type UploadTaskProgressCallback = (res: UploadTaskProgress) => any
/**
* 上传任务
*/
type UploadTask = Promise<uploadFile.Promised> & {
/**
* 上传进度回调
*/
progress: (UploadTaskProgressCallback) => void
/**
* 终止上传任务
*/
abort: () => void
}
type Param = {
/**
* 开发者服务器 url
Expand Down Expand Up @@ -304,7 +329,7 @@ declare namespace TaroH5 {
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network-file.html#wxuploadfileobject
*/
function uploadFile(OBJECT: uploadFile.Param): Promise<uploadFile.Promised>
function uploadFile(OBJECT: uploadFile.Param): uploadFile.UploadTask

namespace downloadFile {
type Promised = {
Expand Down
8 changes: 6 additions & 2 deletions packages/taro-swan/src/native-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ function processApis (taro) {
})
if (key === 'uploadFile' || key === 'downloadFile') {
p.progress = cb => {
task.onProgressUpdate(cb)
if (task) {
task.onProgressUpdate(cb)
}
return p
}
p.abort = cb => {
cb && cb()
task.abort()
if (task) {
task.abort()
}
return p
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/taro-weapp/src/native-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,16 @@ function processApis (taro) {
})
if (key === 'uploadFile' || key === 'downloadFile') {
p.progress = cb => {
task.onProgressUpdate(cb)
if (task) {
task.onProgressUpdate(cb)
}
return p
}
p.abort = cb => {
cb && cb()
task.abort()
if (task) {
task.abort()
}
return p
}
}
Expand Down
27 changes: 26 additions & 1 deletion packages/taro/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,31 @@ declare namespace Taro {
*/
statusCode: number
}
/**
* 上传进度
*/
type UploadTaskProgress = {
progress: number
totalBytesSent: number
totalBytesExpectedToSend: number
}
/**
* 上传进度回调
*/
type UploadTaskProgressCallback = (res: UploadTaskProgress) => any
/**
* 上传任务
*/
type UploadTask = Promise<uploadFile.Promised> & {
/**
* 上传进度回调
*/
progress: (UploadTaskProgressCallback) => void
/**
* 终止上传任务
*/
abort: () => void
}
type Param = {
/**
* 开发者服务器 url
Expand Down Expand Up @@ -735,7 +760,7 @@ declare namespace Taro {
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network-file.html#wxuploadfileobject
*/
function uploadFile(OBJECT: uploadFile.Param): Promise<uploadFile.Promised>
function uploadFile(OBJECT: uploadFile.Param): uploadFile.UploadTask

namespace downloadFile {
type Promised = {
Expand Down