【问题标题】:How to pass csrf token to an upload component from antd?如何将 csrf 令牌从 antd 传递给上传组件?
【发布时间】:2018-02-07 15:08:59
【问题描述】:

在传递 csrf 标记时的表单中,我使用隐藏输入来传递长值。

<Form method="post" action="/account/user" onSubmit={this.onSubmit}>
  <Input name="_csrf" type="hidden" value={this.state.session.csrfToken} onChange={()=>{}}/>
  <FormGroup row>
    <Label sm={2}>Name:</Label>
    <Col sm={10} md={8}>
      <Input name="name" value={this.state.name} onChange={this.handleChange}/>
    </Col>
  </FormGroup>
</Form>

当您有这样的组件时,您是如何做到的?是antd的上传组件。

render() {
  const props = {
    name: 'file',
    action: '//localhost/file/upload',
    onChange(info) {

    }
  };

  return (
    <Dragger {...props}>
      // drag and drop area
    </Dragger>
  )
}

【问题讨论】:

  • 查看data 属性。
  • 感谢您的提示,它最终成为了标题道具。

标签: node.js reactjs csrf antd


【解决方案1】:

最终成为一个可用的道具,称为我可以包含的标题。希望在此过程中对其他人有所帮助。

render() {
            const props = {
                name: 'file',
                action: '//localhost/file/upload',
                headers: {
                   'X-CSRF-Token': 'somelongtokenstring'
                }
                onChange(info) {

                }
            };

            return (
                   <Dragger {...props}>
                       // drag and drop area
                   </Dragger>
    )
    }

【讨论】:

    猜你喜欢
    • 2015-01-31
    • 2018-10-23
    • 2023-04-02
    • 2017-02-17
    • 2015-05-13
    • 2017-03-20
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多