Dropzone发送以“ application / x-www-form-urlencoded”作为内容类型的请求 [英] Dropzone sending a request with 'application/x-www-form-urlencoded' as the content-type

查看:66
本文介绍了Dropzone发送以“ application / x-www-form-urlencoded”作为内容类型的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using dropzone to upload files to my sails backend.

最长的时间里,我一直无法弄清为什么它不起作用。但是,当我将 req 对象放在 console.log 中时,我得到了以下标头(即,是必需的标头):

For the longest time, I have been unable to figure out why it isn't working. However, when I put the req object in the console.log, I got the following headers (i.e., this would be 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-type multipart

I'm guessing this means that dropzone is missing something up, so that it is not sending the request with a content-type of multipart

以下是dropzone代码本身:(请注意,它与dropzone文档中给出的示例紧密相关,但属于一个反应组件)

Here's the dropzone code itself: (Note that it is closely related to the example given in the dropzone docs, but is part of a react component)

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>
      )
  } 

有人会猜测为什么会这样,或者如果我误诊了情况?

Any guesses on why would this would be, or if I am misdiagnosing the situation?

推荐答案

看起来就像实际上是由于我们最终如何设置axios。与此问题相关,与DropZone无关。

Looks like it was actually due to how we were setting up axios in the end. Something related to this issue, and unrelated to DropZone.

这篇关于Dropzone发送以“ application / x-www-form-urlencoded”作为内容类型的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆