gpt4 book ai didi

c# - asp.net mvc 中的 HttpPostedFileBase 状态

转载 作者:行者123 更新时间:2023-11-30 17:56:06 28 4
gpt4 key购买 nike

asp.net mvc 操作采用 HttpPostedFileBase 参数:

public ActionResult Save(HttpPostedFileBase file)
{
//Q1: at the start of this action method, what's the status of this file?
//UploadCompleted or Uploading or something else?

//Q2: where is the file stored? memory or a temp file?

if (answer of Q1 is Uploading)
{
//Q3a: what happens if file.SaveAs is invoked?
//block the current thread until the file is uploaded?
}
else if (answer if Q1 is UploadCompleted)
{
//Q3b: which means the developer can do nothing before the file is uploaded?
//if the business logic limits the size of the file(e.g. <= 5MB), how can we
//prevent evil-intended uploading?
}
}

Q4 在这里:我想记录这个请求的总时间,当用户开始上传文件时,计时器开始。当用户完成上传文件时(或者我的Save 操作是完成),计时结束。我怎么知道用户什么时候开始上传?

最佳答案

首先,看一下这个问题的基础知识:File Upload ASP.NET MVC 3.0

Q1:一旦文件完全可用,就会调用该操作。

Q2:来自 msdn:http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx

The amount of data that is buffered in server memory for a request, which includes file uploads, can be specified by accessing the RequestLengthDiskThreshold property or by setting the requestLengthDiskThreshold attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file.

Q3:您可以在 web.config 中指定最大上传大小:How to increase the max upload file size in ASP.NET?

关于c# - asp.net mvc 中的 HttpPostedFileBase 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14577562/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com