Skip to content

Commit

Permalink
fix(rn): [RN]Taro.uploadFile返回的不是Promise close #4090
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Aug 7, 2019
1 parent 6b9a1ef commit 203eafd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/taro-rn/src/api/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,28 @@ const createFormData = (file, body, name) => {
*/
function uploadFile (opts = {}) {
const {url, filePath, name, header, formData, success, fail, complete} = opts
fetch(url, {
return fetch(url, {
method: 'POST',
body: createFormData(filePath, formData, name),
headers: header
}).then(res => {
if (res.ok) {
console.log('success')
success && success()
complete && complete()
console.log(res)
success && success(res)
complete && complete(res)
return res.json()
} else {
console.log('error')
fail && fail()
complete && complete()
console.log(res)
const errMsg = `uploadFile fail: ${res.status} ${res.statusText}`
fail && fail({errMsg})
complete && complete({errMsg})
return Promise.reject(new Error(errMsg))
}
}).catch(e => {
fail && fail()
complete && complete()
const errMsg = `uploadFile fail: ${e}`
fail && fail({errMsg})
complete && complete({errMsg})
return Promise.reject(new Error(errMsg))
})
}

Expand Down

0 comments on commit 203eafd

Please sign in to comment.