图像上传-本地主机中断
我实现了一个小方法 对于我上传图像的网站。使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看
web.config
的httpRuntime
元素的maxRequestLength
。http://msdn.microsoft.com/en-us/library/e1f13641.aspx
这是您设置最大请求长度的地方。当超过时,运行时会抛出异常。默认大小为 4096KB。
Please take a look at the
maxRequestLength
of thehttpRuntime
element of theweb.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.