测试成功 pickupFile2Server
This commit is contained in:
		
							parent
							
								
									ed70ded908
								
							
						
					
					
						commit
						a813ffd913
					
				
							
								
								
									
										11
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								index.js
									
									
									
									
									
								
							@ -211,6 +211,7 @@ module.exports = {
 | 
				
			|||||||
        // multer 不会自动处理 JSON 数据,必须前后端配合处理
 | 
					        // multer 不会自动处理 JSON 数据,必须前后端配合处理
 | 
				
			||||||
        formData[key] = JSON.stringify(formData[key])
 | 
					        formData[key] = JSON.stringify(formData[key])
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      header._passtoken = uni.getStorageSync('_passtoken')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      uni.showLoading()
 | 
					      uni.showLoading()
 | 
				
			||||||
      let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.makeServerUrl(url), filePath, name, header, formData })
 | 
					      let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.makeServerUrl(url), filePath, name, header, formData })
 | 
				
			||||||
@ -218,8 +219,14 @@ module.exports = {
 | 
				
			|||||||
      // url 所在方法进一步处理后,通过 uploadFile 存在 data 里返回结果
 | 
					      // url 所在方法进一步处理后,通过 uploadFile 存在 data 里返回结果
 | 
				
			||||||
      uni.hideLoading()
 | 
					      uni.hideLoading()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (data) {
 | 
					      try{ // 不知为何,返回的 data 是字符串而不是对象
 | 
				
			||||||
        return { _state: 'SUCCESS', fileUrl: data ? this.makeServerUrl(data.webpath || data.path) : undefined, ...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 {
 | 
					      }else {
 | 
				
			||||||
        return { _state: 'CLIENT_FAIL_UPLOAD_FILE', errorUpload }
 | 
					        return { _state: 'CLIENT_FAIL_UPLOAD_FILE', errorUpload }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user