Dropzone sending a request with 'application/x-www-form-urlencoded' as the content-type

家住魔仙堡 提交于 2020-01-17 06:43:13

问题


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

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' 
  },

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

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?

来源:https://stackoverflow.com/questions/44039671/dropzone-sending-a-request-with-application-x-www-form-urlencoded-as-the-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!