我怎样才能“附着”? ASP.NET 字节数组到“文件”在表单上输入字段?
在我的 ASP.NET 应用程序中,我想向第三方文档编辑服务发出 POST 请求 (Zoho)。我了解如何使用前端表单发出此请求,以及如何在 VB.NET 代码隐藏中发出此请求。但是,由于我发送的文件作为字节数组存储在数据库中,并且 POST 结果(Zoho 网站上的编辑器页面)必须显示在特殊的“目标”(新窗口或 iframe)中,因此看起来我需要两者的一些奇怪的组合。
基本上,我想将此字节数组的内容附加
Dim fileContents() As Byte = Files.get(fileId)
到此表单中的文件输入字段
<form id="theForm" action="http://zohoservice" method="POST" target="_blank" >
...
<input type="file" name="fileContents" />
</form>
,然后通过 JavaScript 提交它,就像这样
theForm.submit();
我希望我不会要求不可能的事情。感谢您的帮助!
In my ASP.NET application, I want to make a POST request out to a third-party, document editing service (Zoho). I understand how to make this request with a front-end form, and how to make one in my VB.NET code-behind. However, since I the file I'm sending is stored in my database as a byte array and the POST results (an editor page on the Zoho website) must be displayed in a special 'target' (new window or an iframe), it looks like I need some weird combination of both.
Basically, I want to attach the content of this byte array
Dim fileContents() As Byte = Files.get(fileId)
to the file input field in this form
<form id="theForm" action="http://zohoservice" method="POST" target="_blank" >
...
<input type="file" name="fileContents" />
</form>
and then submit it via javascript like this
theForm.submit();
I hope I'm not asking for the impossible. Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你实际上不能按照你的建议去做。使用
时,上传的文件永远不会加载到 HTML 中。相反,它作为 POST 请求的一部分包含在内。因此,您实际要做的是制作一个完整的 POST 请求,并将该帖子提交到您的操作 (http://zohoservice)。
这是可行的,但您需要做一些工作,并且您需要了解如何创建 MIME 多部分 POST 请求。如果有任何反机器人技术或视图状态跟踪(诸如此类的东西),那么您就会遇到一些麻烦。
You actually can't do what you're suggesting. When using an
<input type="file" .../>
the uploaded file is never loaded into the HTML. Instead it's included as part of the POST request. So what you want to actually do is craft a complete POST request, and submit that post to your action (http://zohoservice).This is doable, but it's going to be a bit of work on your end, and you'll need to understand how to create a MIME multipart POST request. And if there are any anti-botting technologies or view state tracking (kinds of things) then you'll run into some trouble there.