Dropzone 以 'application/x-www-form-urlencoded' 作为 content-type 发送请求
Dropzone sending a request with 'application/x-www-form-urlencoded' as the content-type
我正在使用 dropzone 将文件上传到我的 sails 后端。
很长一段时间以来,我一直无法弄清楚为什么它不起作用。但是,当我将 req
object 放在 console.log
中时,我得到以下 headers(即,这将是 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
的请求
这是 dropzone 代码本身:(请注意,它与 dropzone 文档中给出的示例密切相关,但它是反应组件的一部分)
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>
)
}
有没有关于为什么会这样的猜测,或者我是否误诊了这种情况?
看起来这实际上是由于我们最终设置 axios 的方式所致。与 this issue 相关但与 DropZone 无关的内容。
我正在使用 dropzone 将文件上传到我的 sails 后端。
很长一段时间以来,我一直无法弄清楚为什么它不起作用。但是,当我将 req
object 放在 console.log
中时,我得到以下 headers(即,这将是 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
这是 dropzone 代码本身:(请注意,它与 dropzone 文档中给出的示例密切相关,但它是反应组件的一部分)
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>
)
}
有没有关于为什么会这样的猜测,或者我是否误诊了这种情况?
看起来这实际上是由于我们最终设置 axios 的方式所致。与 this issue 相关但与 DropZone 无关的内容。