From a813ffd9139d9f922efe4904b377f7b54b03324f Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Fri, 15 Oct 2021 22:02:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=88=90=E5=8A=9F=20pickupFi?= =?UTF-8?q?le2Server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 431175f..115230e 100644 --- a/index.js +++ b/index.js @@ -211,6 +211,7 @@ module.exports = { // multer 不会自动处理 JSON 数据,必须前后端配合处理 formData[key] = JSON.stringify(formData[key]) } + header._passtoken = uni.getStorageSync('_passtoken') uni.showLoading() let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.makeServerUrl(url), filePath, name, header, formData }) @@ -218,8 +219,14 @@ module.exports = { // url 所在方法进一步处理后,通过 uploadFile 存在 data 里返回结果 uni.hideLoading() - if (data) { - return { _state: 'SUCCESS', fileUrl: data ? this.makeServerUrl(data.webpath || data.path) : undefined, ...data } + try{ // 不知为何,返回的 data 是字符串而不是对象 + data = JSON.parse(data) + }catch(exp){ + return { _state: 'CLIENT_FAIL_RESPONSE_JSON_MALFORMED'} + } + + if (data?._state==='SUCCESS') { + return { _state: 'SUCCESS', fileUrl: this.makeServerUrl(data.webpath || data.path), ...data } }else { return { _state: 'CLIENT_FAIL_UPLOAD_FILE', errorUpload } }