[英]Upload File Using Extjs
嗨,我已经编写了用于上传文件并将其插入数据库的代码,因此我需要获取上传文件的字节。
这是我的代码:
{ xtype: 'filefield', id: 'AttachData', name: 'file-path', emptyText: 'Upload the document...', margin: "15 0 0 0", buttonText: 'Browse', msgTarget: 'side', allowBlank: false, anchor: '100%', disabled: false }, { xtype: 'button', text: 'Upload', margin: "15 0 0 10", handler: function() { var form = this.up('form').getForm(); if (form.isValid()) { form.submit({ url: '../UploadAttachment.aspx', headers: { 'Content-type': 'application/json;charset=utf-8' }, waitMsg: 'Uploading your file...', success: function(response, action) { isUploded = true; msg('Success', 'Processed file "' + action.result.file + '" on the server'); }, failure: function(response, action) { console.log(action); Ext.Msg.alert('Failed', response.message ? action.result.message : 'No response'); } }); } } },
任何人都可以帮助我解决这个问题。 需要获取上传文件的字节。
当您的请求将转到“ UploadAttachment.aspx”页面时,只需在此处创建一个函数即可获取上传的文件详细信息,并使用URL指定函数名称。 这样该函数可以轻松地调用服务器端或aspx页面。
您可以使用以下代码获取上载文件的完整详细信息。
HttpPostedFile uploadFile = Context.Request.Files["file-path"];
现在,您可以在uploadFile变量中获取有关上传文件的所有信息。
防爆。
uploadFile.InputStream
uploadFile.FileName
and all others.
Default.aspx(编码)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Libraries/ext-all.js"></script>
<script src="Libraries/ext-all-debug.js"></script>
<link href="Libraries/ext-theme-crisp-all-debug.css" rel="stylesheet" />
<script type="text/javascript">
Ext.onReady(function () {
var window = new Ext.Window({
id: 'grdWindow',
width: 400,
items: [
{
xtype: 'form',
renderTo: Ext.getBody(),
items: [
{
xtype: 'filefield',
id: 'AttachData',
name: 'file-path',
emptyText: 'Upload the document...',
margin: "15 0 0 0",
buttonText: 'Browse1',
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
disabled: false
}, {
xtype: 'button',
text: 'Upload',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: 'Default.aspx',
headers: {
'Content-type': 'application/json;charset=utf-8'
},
waitMsg: 'Uploading your file...',
success: function (response, action) {
isUploded = true;
msg('Success', 'Processed file "' + action.result.file + '" on the server');
},
failure: function (response, action) {
console.log(action);
Ext.Msg.alert('Failed', response.message ? action.result.message : 'No response');
}
});
}
}
}
]
}
]
}).show();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs(处理程序)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpPostedFile fileUpload = HttpContext.Current.Request.Files["file-path"];
if (fileUpload != null)
{
//You can get here anything from fileUpload
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.