图像上传-本地主机中断

发布于 2024-12-15 10:14:09 字数 613 浏览 7 评论 0原文

我实现了一个小方法 对于我上传图像的网站。使用 FileUpload 控件,我选择一个图像,然后当我点击按钮时,会生成 UploadImage() 方法。

UploadImage() 方法将图像存储在服务器的文件夹中,并将其路径存储在数据库中。它还检查图像的文件大小,如果大于兆字节,则显示警报,否则上传并存储图像。已使用 45KB 到 900KB 的一些图像对此进行了测试。它运作得很完美。

问题

当使用一些大约 4MB 的图像进行测试时,有时会显示“错误”,因为它大于 1MB,但有时(我不知道为什么),Google Chrome 会指示我到一个页面告诉我本地主机已被中断。

调试的时候我连按钮上传点击方法都不输入!我觉得这很奇怪。图像的扩展名似乎不是问题,因为我正在使用 .jpg 和 .png 进行测试。

有人遇到过同样的问题吗?有大师可以帮助我吗?

非常感谢。


更新:

4052kb 的文件似乎已正常工作(即显示错误消息) 但文件超过 4098kb)导致本地主机中断。当按钮被点击时, 下面的浏览器显示“发送请求”和上传 (0%),并显示“与本地主机的连接已中断”。

I have implemented a small method
for my site where I upload an image. using a FileUpload control, I choose an image, and then when I hit a button, the UploadImage() method is generated.

The UploadImage() method stores the image in a folder in the server and stores its path in the Database. It also checks the file size of the image, if greater than a megabyte, an alert is displayed, else, the image is upload and stored. This has been tested with a few images ranging from 45KB to 900KB. It has worked perfectly.

THE PROBLEM:

When tested with a few images of approximately 4MB, sometimes it shows the 'error' since it is greater than 1MB, but at other times (I do not know why), Google Chrome directs me to a page telling me that the localhost has been interrupted.

When debugging, I do not even enter the button Upload click method! I find this very strange. The extension of the image doesn't seem to be the problem since I am testing with .jpg and .png.

Did some one experience the same problem? Is there a guru that can help me?

Thank you very much.


update:

it seems that files of 4052kb have worked correctly (i.e. an error message was displayed)
but files over 4098kb) resulted in a local host interrupt. When the button is clicked,
the browser below shows 'sending request' and uploading (0%) and displays "The connection to localhost was interrupted."

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

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

发布评论

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

评论(1

苍风燃霜 2024-12-22 10:14:09

请查看 web.confighttpRuntime 元素的 maxRequestLength

http://msdn.microsoft.com/en-us/library/e1f13641.aspx

这是您设置最大请求长度的地方。当超过时,运行时会抛出异常。默认大小为 4096KB。

Please take a look at the maxRequestLength of the httpRuntime element of the web.config.

http://msdn.microsoft.com/en-us/library/e1f13641.aspx

This is where you set the maximum request length. When it is exceeded, the runtime throws an exception. The default size is 4096KB.

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