Ext.Direct File Upload-类型为application/json的表单提交 [英] Ext.Direct File Upload - Form submit of type application/json
问题描述
我正在尝试使用Ext.Direct通过表单提交上传文件,但是Ext.direct将我的请求发送为"application/json"类型,而不是"multipart/form-data"
I am trying to upload a file through a form submit using Ext.Direct, however Ext.direct is sending my request as type 'application/json' instead of 'multipart/form-data'
这是我的表格.
{
xtype: 'form',
api: {
submit: 'App.api.RemoteModel.Site_Supplicant_readCSV'
},
items: [
{
xtype: 'filefield',
buttonOnly: false,
allowBlank: true,
buttonText: 'Import CSV'
}
],
buttons:
[
{
text: 'Upload',
handler: function(){
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
waitMsg: 'Uploading...',
success: function(form, action){
console.log(action.result);
}
});
}
}
}
]
},
在HTTP请求上,它将检查请求选项是否为表单上载.
On the HTTP request, it checks to see if the request options is a form upload.
if (me.isFormUpload(options)) {
到达这里
isFormUpload: function(options) {
var form = this.getForm(options);
if (form) {
return (options.isUpload || (/multipart\/form-data/i).test(form.getAttribute('enctype')));
}
return false;
},
getForm: function(options) {
var form = options.form || null;
if (form) {
form = Ext.getDom(form);
}
return form;
},
但是,选项看起来像这样
However, options looks like this
{
callback: function (options, success, response) {
jsonData: Object
action: "RemoteModel"
data: Array[1]
0: form
length: 1
__proto__: Array[0]
method: "Site_Supplicant_readCSV"
tid: 36
type: "rpc"
__proto__: Object
scope: constructor
timeout: undefined
transaction: constructor
}
并且没有直接的形式配置,但是它存在于jsonData.data [0]中.因此,它不会将其设置为multipart/form-data类型,而是作为application/json类型发送出去. 我究竟做错了什么?为什么无法正确提交表单?
And there is no direct form config, but it exists in jsonData.data[0]. So it doesn't set it as type multipart/form-data and it gets sent off as type application/json. What am I doing wrong? Why isn't the form getting submitted properly?
编辑-我看到了很多有关Ext.Direct的'formHandler'配置的讨论?我被引导假定此配置可以解决我的问题.但是我不知道这应该在哪里.如果可以找到解决方案,我将更新我的帖子.
Edit - I am seeing a lot of discussion about a 'formHandler' config for Ext.Direct? I am being led to assume this config could solve my issue. However I don't know where this should exist. I'll update my post if I can find the solution.
解决方案-只需在参数末尾添加/ formHandler /即可设置标志并解决了我的问题.莫名其妙.
Solution - Simply adding /formHandler/ to the end of the params set the flag and solved my issue. Baffled.
Supplicant.prototype.readCSV = function(params,callback, request, response, sessionID/*formHandler*/)
{
var files = request.files;
console.log(files);
};
推荐答案
处理文件上传请求的方法应在 服务器端提供的Ext.Direct API.
The method that handles file upload requests should be marked as formHandler
in the
Ext.Direct API provided by the server side.
编辑:您正在使用App.api.RemoteModel.Site_Supplicant_readCSV
方法上传文件;此方法必须为formHandler
.
EDIT: You are using App.api.RemoteModel.Site_Supplicant_readCSV
method to upload files; this method needs to be a formHandler
.
I'm not very familiar with Node.js stack but looking at this example suggests that you may need to add /*formHandler*/
descriptor to the function's declaration on the server side.
这篇关于Ext.Direct File Upload-类型为application/json的表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!