ASP.NET 请求 - 我可以从客户端上创建的动态控件获取发布的文件吗?
我有一个带有一些自定义 JavaScript 的 Web 控件。 JavaScript 使用类似于以下的代码在客户端动态创建新的文件上传控件:
var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
container.appendChild(newFileUpload); // where container is a div
这存在于 encType 设置为 multipart/form-data 的 ASP.NET 表单中。 我将在页面上有 1 - n 个控件(当然,限制在合理的数量内)。
我现在想在 ASP.NET 应用程序中捕获上传的文件。 由于上述方法,我知道我无法像从 FileUpload 控件(不幸的是我无法使用)那样捕获它们。 还有其他方法可以捕获上传的文件吗?
我已经浏览了多个区域,包括:
- Request.Files
- Request.Form
- Request.Form.Keys
- Request.InputStream
但我一直无法找到内容。 我相信客户端正确提交了这些数据,但无法确定服务器如何处理原始请求信息(如果甚至公开)。
有人对我可以进一步探索的领域有任何建议吗?
谢谢
I have a web control with some custom javascript. The javascript creates new file upload controls on the client dynamically using code similar to:
var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
container.appendChild(newFileUpload); // where container is a div
This exists in an ASP.NET form with encType set to multipart/form-data. I will have 1 - n controls on the page (well, limited to a reasonable number, of course).
I now would like to capture the uploaded files in my ASP.NET application. Because of the approach taken above I know that I cannot capture them as I would from a FileUpload control (which unfortunately I cannot use). Is there another way to capture the uploaded files?
I have looked through a number of areas, including:
- Request.Files
- Request.Form
- Request.Form.Keys
- Request.InputStream
But I have not been able to find the content. I believe the client is submitting this data correctly but have been unable to determine what the server does with the raw request information (if this is even exposed).
Does anyone have any suggestions on areas I might further explore?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该向上传元素添加一个唯一名称,以从 Request.Form 集合中获取它。
,您可以通过以下方式获取内容
编辑:我尝试了 id 和 name 属性,如果您应该将下面的属性添加到表单元素中 。 这允许您通过 Request.Files["file01"] 获取文件内容:
You should add a unique name to your upload element to get it from Request.Form collection.
EDIT : I tried id and name attibutes, the with name, you can get the content by
Also if you should add the attribute below to your form element. This allows you to get the file content by Request.Files["file01"] :