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

Upload 在回调onChange事件时,response为undefined #2521

Closed
xuqiang1227 opened this issue Jul 27, 2016 · 13 comments
Closed

Upload 在回调onChange事件时,response为undefined #2521

xuqiang1227 opened this issue Jul 27, 2016 · 13 comments

Comments

@xuqiang1227
Copy link

xuqiang1227 commented Jul 27, 2016

本地环境

  • antd 版本: 1.6.5
  • 操作系统及其版本: windows 10
  • 浏览器及其版本: chrome

你做了什么?

使用Upload上传组件时,回调onChange时,file.response为undefined。
之前的版本(很早,大概是1.4版本左右)是没有问题的,可以正常获取数据,最近升级后出现的问题。

你期待的结果是:

在回调onChange时,file.response为服务端返回的数据。

实际上的结果:

file.response为undefined。

@benjycui
Copy link
Contributor

Please provide a re-producible demo: http://codepen.io/anon/pen/wGOWGW?editors=001

@benjycui
Copy link
Contributor

@xuqiang1227
Copy link
Author

就是和官方的例子写的。
刚做的时候是正常的,测试也没有问题,最近升级后才出现的。

@benjycui
Copy link
Contributor

Please provide a re-producible demo: http://codepen.io/anon/pen/wGOWGW?editors=001

@xuqiang1227
Copy link
Author

xuqiang1227 commented Jul 28, 2016

如何提供呀?服务端都是本地局域网服务器。
upload的组件使用方式和官方的例子一样。
onChange事件这样的:

getUploadLogo(info) {
        let {fileList} = info;
        let {file} = info;

        if (file.response) {    //这里永远都是undefined,但是接口确实返回了数据。
            //... ...
        }
    }

image
等onChange结束后,后台才返回数据:
image
后台返回数据后,再没有调用onChange事件。

@afc163
Copy link
Member

afc163 commented Jul 28, 2016

把你使用 upload 的完整代码贴一下。

@xuqiang1227
Copy link
Author

xuqiang1227 commented Jul 28, 2016

constructor:

this.state = {fileList: []};
this.getUploadLogo = this.getUploadLogo.bind(this);

onChange事件:

getUploadLogo(info) {
        let {fileList} = info;
        let {file} = info;

        if (file.response) {
            const result = file.response;
            if (result.status && result.status === 1) {
                ReservationDialog({type: DialogType.ERROR, message: file.response.msg, locale: this.props.intl.formatMessage({id: 'locale'})});
            } else if (result && result.status === 0) {
                if (result.data) {
                    for (const key in result.data) {
                        this.avatar = result.data[key];
                    }
                    //noinspection JSUnresolvedFunction
                    this.setState({fileList});
                }
            }
        }
    }

render中定义如下:

render() {
     const avatarProps = {
            name: 'fileUpload',
            action: '/iwork/file/uploadFile?token=' + sessionStorage.getItem('token') +  '&_=' + Date.now(),
            onChange: this.getUploadLogo,
            multiple: false
        };

       //……

      <span className="upload">
          <Upload {...avatarProps} fileList={this.state.fileList}>
              <Icon type="plus"/>
           </Upload>
       </span>

}

@afc163
Copy link
Member

afc163 commented Jul 28, 2016

#2423

@xuqiang1227
Copy link
Author

把setState放到if(file.response)外就可以了。
我这里的问题得到解决。
感谢@afc163

@afc163
Copy link
Member

afc163 commented Jul 28, 2016

请关掉 issue 。

@afc163
Copy link
Member

afc163 commented Jul 29, 2016

完全不理我。

@afc163 afc163 closed this as completed Jul 29, 2016
@xuqiang1227
Copy link
Author

sorry,今天请假了。没能及时回复!!@afc163

@lock
Copy link

lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants