IIS asp.net mvc的部分?上传文件 [英] IIS asp.net mvc partial? file upload

查看:96
本文介绍了IIS asp.net mvc的部分?上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,我希望有人能告诉我一些关于到底是怎么回事幕后...

Given the following code which is extremely generic, I was hoping someone could tell me a bit about what is going on behind the scenes...

[HttpPost]
public ActionResult Load(Guid regionID, HttpPostedFileBase file)
{
    if (file.ContentLength == 0)
        RedirectToAction("blablabla.....");

    var fileBytes = new byte[file.ContentLength];
    file.InputStream.Read(fileBytes, 0, file.ContentLength);
}

具体来说,就是我的操作方法之前完全上传到服务器上的文件被调用?抑或是导致或相当等待整个文件上传file.InputStream.Read()方法调用。我可以做局部读取的流,因为它被上传访问该文件的块? (如果调用我的方法之前,整个火上载,然后它是所有一个有争议的问题。)

Specifically, is the file completely uploaded to the server before my action method is invoked? Or is it the file.InputStream.Read() method call that causes or rather waits for the entire file to upload. Can I do partial reads on the stream and gain access to the "chunks" of the file as it is uploaded? (If the entire fire is uploaded before my method is invoked then it is all a moot point.)

任何人都可以点我就在这里的内部运作一些好的信息。有IIS6或II7这里有什么区别?

Can anyone point me to some good info on the inner workings here. Is there any difference between IIS6 or II7 here?

谢谢,

推荐答案

该文件时需要调用操作方法之前被发送到服务器。从文档报价:

The while file needs to be sent to the server before the action method is invoked. Quote from the documentation:

文件上传在MIME
  的multipart / form-data的格式。通过
  默认情况下,所有的请求,包括表单
  田野和上传文件,大于
  256 KB的缓冲到磁盘上,而
  比在服务器内存中举行。

Files are uploaded in MIME multipart/form-data format. By default, all requests, including form fields and uploaded files, larger than 256 KB are buffered to disk, rather than held in server memory.

您可以指定最大允许
  通过访问请求大小
  maxRequestLength的属性,或者
  设置maxRequestLength属性
  在的httpRuntime元素(ASP.NET
  内设置架构)元素
  的Machine.config或Web.config文件。该
  默认值是4 MB。

You can specify the maximum allowable request size by accessing the MaxRequestLength property or by setting the maxRequestLength attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file. The default is 4 MB.

这是在缓冲的数据的量
  服务器存储器的请求,其
  包括文件上传,可
  通过访问指定
  RequestLengthDiskThreshold财产或
  通过设置
  requestLengthDiskThreshold属性
  在的httpRuntime元素(ASP.NET
  内设置架构)元素
  的Machine.config或Web.config文件。

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.

服务器的内存不会在服务器上进行消费,但该文件的内容将被缓冲到磁盘。一旦客户端发送整个文件中的ASP.NET管道将调用你的控制器动作,你可以读取数据块请求流,并将其保存到另一个文件,这将是上传文件的确切位置。之前该文件已完成上传,因为可能在文件后,随之而来的的multipart / form-data的其他一些领域的行动不能被援引,他们将不会被分配在这种情况下

Server memory won't be consumed on the server but the file contents will be buffered to disk. Once the client has sent the whole file the ASP.NET pipeline will invoke your controller action and you could read the request stream in chunks and save it to another file which will be the definitive location of the uploaded file. The action cannot be invoked before the file has finished uploading as there might be some other fields in the multipart/form-data that come after the file and they won't be assigned in this case.

这篇关于IIS asp.net mvc的部分?上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆