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

Taro.uploadFile 设置 header 不生效 #9259

Closed
twoheartliu opened this issue May 6, 2021 · 0 comments
Closed

Taro.uploadFile 设置 header 不生效 #9259

twoheartliu opened this issue May 6, 2021 · 0 comments
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@twoheartliu
Copy link

相关平台

H5

浏览器版本: Chrome 90
使用框架: React

复现步骤

const uploadTask = Taro.uploadFile({
    url: `/openapi/${query}`,
    filePath: files[0],
    name: 'file',
    formData: {
      user: 'test',
    },
    header: { token: '123', abc: 'abc' },
    success: function(res) {
      var data = res.data
      //do something
      return data
    },
  })
  uploadTask.progress(res => {
    console.log('上传进度', res.progress)
    console.log('已经上传的数据长度', res.totalBytesSent)
    console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
  })
  uploadTask.abort() // 取消上传任务

期望结果

headers 显示 token

实际结果

Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6,ko;q=0.5,ja;q=0.4
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 1354
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarypnWFAxyBMAiBz5zp
DNT: 1
Host: 10.0.2.135:10086
Origin: http://10.0.2.135:10086
Pragma: no-cache
Referer: http://10.0.2.135:10086/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1

环境信息

👽 Taro v3.1.4


  Taro CLI 3.1.4 environment info:
    System:
      OS: macOS 11.3
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node
      Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.3/bin/yarn
      npm: 7.6.3 - ~/.nvm/versions/node/v12.16.3/bin/npm
    npmPackages:
      @tarojs/cli: 3.1.4 => 3.1.4 
      @tarojs/components: 3.1.4 => 3.1.4 
      @tarojs/mini-runner: 3.1.4 => 3.1.4 
      @tarojs/react: 3.1.4 => 3.1.4 
      @tarojs/runtime: 3.1.4 => 3.1.4 
      @tarojs/taro: 3.1.4 => 3.1.4 
      @tarojs/webpack-runner: 3.1.4 => 3.1.4 
      babel-preset-taro: 3.1.4 => 3.1.4 
      eslint-config-taro: 3.1.4 => 3.1.4 
      react: ^17.0.0 => 17.0.2 
      taro-ui: ^3.0.0-alpha.10 => 3.0.0-alpha.10 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels May 6, 2021
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

No branches or pull requests

1 participant