Extjs将Excelfile upload到WCF Restful服务

我想上传一个文件到wcf服务,并让它读取excel文件,并以json格式将文件中的数据返回给我。 有关如何在estjs中创buildfile upload的sencha示例,请参阅下面的代码

Ext.create('Ext.form.Panel', { renderTo: 'fi-form', width: 500, frame: true, title: 'File Upload Form', bodyPadding: '10 10 0', defaults: { anchor: '100%', allowBlank: false, msgTarget: 'side', labelWidth: 50 }, items: [{ xtype: 'textfield', fieldLabel: 'Name' },{ xtype: 'filefield', id: 'form-file', emptyText: 'Select an Excel', fieldLabel: 'Excel', name: 'Excel-path', buttonText: '', buttonConfig: { iconCls: 'upload-icon' } }], buttons: [{ text: 'Save', handler: function(){ var form = this.up('form').getForm(); if(form.isValid()){ form.submit({ url: 'rest/upload.svc', waitMsg: 'Uploading your file...', success: function(fp, o) { msg('Success', 'Processed file "' + o.result.file + '" on the server'); } }); } } },{ text: 'Reset', handler: function() { this.up('form').getForm().reset(); } }] }); 

我的问题是,在我的rest服务服务期待什么样的数据types?

在客户端代码中,就像将整个表单发回服务一样,我可以使用request.Form(“Excel-path”)来获取excel文件吗?

这是一个好办法吗? 我曾尝试读取客户端使用的Excel文件

 ActiveXObject("Excel.Application") 

但它只适用于IE,它需要改变IE中的一些ActiveX设置,这就是为什么我正在考虑使用服务来读取文件。 想知道有没有其他的办法呢。

ExtJS将创build一个隐藏的iFrame并通过该iFrame中的表单将该文件发布到您的服务器。

您的服务器应该有一个可接受多部分forms的POST的URL。

ExtJS期望从您的服务器的HTML响应。

发送到服务器:

 Content-Type: multipart/form-data... POST /files Request Payload... 

服务器返回:

 Status: 201 Created Content-Type: text/html { success:true, id:123, link:"/files/123" } 

您的服务器还应该有一个可以返回文件表示的控制器:

发送到服务器:

 GET /files/123 Accept: application/json 

服务器返回:

 Status: 200 OK Content-type: application/json { id:123, fileName:"somefile.xls", someData:"..." } 

所以你需要做两件事情:将文件发送到服务器以获取链接,然后使用链接从服务器获取文件。