【问题标题】:Dropzone sending a request with 'application/x-www-form-urlencoded' as the content-typeDropzone 发送以“application/x-www-form-urlencoded”作为内容类型的请求
【发布时间】:2017-05-18 05:58:47
【问题描述】:

我正在使用 dropzone 将文件上传到我的 Sails 后端。

很长一段时间以来,我一直无法弄清楚它为什么不起作用。但是,当我将 req 对象放入 console.log 时,我得到了以下标头(即,这将是 req.headers):

headers:
  { 'x-id': 'vendor-______________',
  'x-token': '_______________',
  host: 'localhost:1337',
  'content-type': 'application/x-www-form-urlencoded',
  'content-length': '0',
  connection: 'close' 
  },

我猜这意味着 dropzone 丢失了一些东西,因此它不会发送带有 content-typemultipart 的请求

这是 dropzone 代码本身:(请注意,它与 dropzone 文档中给出的示例密切相关,但它是 react 组件的一部分)

Component.add("DropzoneComponent", {
  getDefaultProps: function(){
    return {}
  },
  componentDidMount: function() {
      var c = this
      var field = new Dropzone(c.refs.dropzone, {
          url: c.props.url,
          paramName: "csv"
      });
      field.on("error", function(fileObject, err) {
        console.log("dropzone file object:", fileObject, "***Error message***", err);  
      })  
      field.on("success", function(fileObject, file){
          console.log("file object", fileObject, "file:", file);
      })  

  render: function(){
      return (
          <span>
            <input type="hidden" value={this.state.image || ""} name={this.props.name || ""} />
            <div id="upload-field" ref="dropzone" type="file" className="dropzone"></div>
          </span>
      )
  } 

任何猜测为什么会这样,或者我是否误诊了这种情况?

【问题讨论】:

  • 你能显示dropzone代码吗?
  • @AgamBanga 我可以,好主意;刚刚进行了编辑
  • @RyanQuey 你在使用 react-dropzone 包吗?
  • @Glen 实际上,既然你提到了它,它就在项目节点模块文件夹中,但我不确定它是否实现了

标签: http-headers dropzone.js


【解决方案1】:

看起来这实际上是由于我们最终设置 axios 的方式。与this issue 相关的内容,与 DropZone 无关。

【讨论】:

    猜你喜欢
    • 2015-04-02
    • 2018-04-04
    • 2021-01-01
    • 2019-12-24
    • 2021-02-03
    • 1970-01-01
    • 2021-06-17
    • 2020-04-21
    • 2017-12-18
    相关资源
    最近更新 更多