gpt4 book ai didi

javascript - 使用Extjs上传文件

转载 作者:行者123 更新时间:2023-11-28 00:01:40 24 4
gpt4 key购买 nike

嗨,我已经编写了一个用于上传文件并插入数据库的代码,所以我需要获取上传文件的字节。

这是我的代码:

{
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
}
}

}

关于javascript - 使用Extjs上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31739967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com