ASP.net 文件操作延迟

发布于 2024-08-17 06:27:33 字数 551 浏览 1 评论 0原文

好的,问题来了:我正在从 FileUpload 控件读取流,以 n 个字节的块读取并循环写入数组,直到到达流的末尾。

现在我这样做的原因是因为我需要在上传仍在进行时检查几件事(而不是执行 Save(); 一次性完成整个事情)。问题是:当从本地计算机执行此操作时,我可以很好地看到文件,因为它正在上传并且其大小增加(必须在循环中添加一个 Sleep(); 子句才能真正看到正在写入的文件)。

但是,当我从远程计算机上传文件时,直到文件上传完成后我才看到它。另外,我还添加了另一个调用,以便在进度进行时将进度写入文本文件,并且我得到了同样的结果。本地:文件随着上传的进行而更新,远程:令牌文件仅在上传完成后出现(这有点无用,因为我在上传仍在进行时需要它)。

(或 ASP.net)中是否存在某种安全设置,可以将文件保存在远程计算机的临时位置(而不是本地计算机),然后将它们移动到指定的目的地?我将其与从本地计算机(甚至在公共主机名)浏览时显示错误消息的 ASP.net 进行比较,而不是从远程计算机浏览时显示的通用编译错误页面/通用异常页面(并且 customErrors 不是关)

有任何线索吗?

提前致谢。

Ok, so here's the problem: I'm reading the stream from a FileUpload control, reading in chunks of n bytes and writing the array in a loop until I reach the stream's end.

Now the reason I do this is because I need to check several things while the upload is still going on (rather than doing a Save(); which does the whole thing in one go). Here's the problem: when doing this from the local machine, I can see the file just fine as it's uploading and its size increases (had to add a Sleep(); clause in the loop to actually get to see the file being written).

However, when I upload the file from a remote machine, I don't get to see it until the the file has completed uploading. Also, I've added another call to write the progress to a text file as the progress is going on, and I get the same thing. Local: the file updates as the upload goes on, remote: the token file only appears after the upload's done (which is somewhat useless since I need it while the upload's still happening).

Is there some sort of security setting in (or ASP.net) that maybe saves files in a temporary location for remote machines as opposed to the local machine and then moves them to the specified destination? I would liken this with ASP.net displaying error messages when browsing from the local machine (even on the public hostname) as opposed to the generic compilation error page/generic exception page that is shown when browsing from a remote machine (and customErrors are not off)

Any clues on this?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言月老 2024-08-24 06:27:33

FileUpload 控件呈现为 HTML 元素;这样,您的浏览器将打开该文件,读取所有内容,编码并发送它。

您的 ASP.NET 请求在 IIS 收到所有浏览器数据后才开始。

这样,您需要编写一个客户端组件(Flash、Java 小程序、Silverlight)来以小块形式发送文件并在服务器端重建该文件。

编辑:一些信息在MSDN上

要控制在处理请求时上传的文件是临时存储在内存中还是服务器上,请设置 httpRuntime 元素的 requestLengthDiskThreshold 属性。此属性使您能够管理输入流缓冲区的大小。默认值为 256 字节。您指定的值不应超过您为 maxRequestLength 属性指定的值。

FileUpload control renders as an <input type="file"> HTML element; this way, your browser will open that file, read ALL content, encode and send it.

Your ASP.NET request just starts after IIS receives all browser data.

This way, you'll need to code a client component (Flash, Java applet, Silverlight) to send a file in small chunks and rebuild that at server-side.

EDIT: Some information on MSDN:

To control whether the file to upload is temporarily stored in memory or on the server while the request is being processed, set the requestLengthDiskThreshold attribute of the httpRuntime element. This attribute enables you to manage the size of the input stream buffer. The default is 256 bytes. The value that you specify should not exceed the value that you specify for the maxRequestLength attribute.

你げ笑在眉眼 2024-08-24 06:27:33

我了解您想要检查正在上传的文件的内容。
如果这是您的要求,那么为什么不在从 HttpPostedFile 读取文件时添加一个文本框并填充它。

I understand that you want to check the file which is being uploaded for it's content.
If this is your requirement then why not add a textbox and populate it while you are reading the file from HttpPostedFile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文