【问题标题】:Uploadify setting file size limitUploadify 设置文件大小限制
【发布时间】:2012-12-13 16:31:02
【问题描述】:

我正在做一个项目,我使用 uploadify 控件进行文件上传,我必须将文件大小限制设置为 5MB,我看过它的文档 Here

我尝试设置 5MB,但当我选择 3MB 左右的文件时,它仍然显示文件大小错误 我也尝试设置没有任何单位的值(即 5120),但在这种情况下,当我选择文件 3MB 大小时,它也会显示文件大小错误

这是我的代码

var sizelimit = '5MB'; //or '5120'
$('#file_upload').uploadify({
        'uploader': ResourceUplodify.Uploader,
        'script': ResourceUplodify.ScriptFile,
        'cancelImg': ResourceUplodify.CancelImg,
        'folder': ResourceUplodify.Folder,
        'fileDesc': 'Document Files',
        'buttonImg': '../../Content/images/Attach-File.jpg',
        'fileExt': '*.pdf;*.doc;*.ppt;*.odt;*.rtf;*.txt',
        // 'sizeLimit': 10485760,
        'sizeLimit': sizelimit,
        'height': 29,
        'width': 90,
        'buttonText': 'Attach File',
        'multi': false,
        'auto': false,
        'onSelect': function (a, b, c, d, e) {          
        },
        'onComplete': function (a, b, c, d, e) {
            //            if (d != '1') {          
        },
        'onError': function () {

        }
    });

我也想通过 uploadify 使用 session,他们展示了使用 session 的 PHP 代码,但我不知道如何在 C# 中使用 session(使用uploadify offcourse)

Working with Session in Uploadify

如何在 MVC3(C# 代码)中访问 formdata 的值

【问题讨论】:

    标签: c# asp.net-mvc-3 uploadify


    【解决方案1】:

    Uploadify 上的文件大小限制管理 - Aspnet 基于 2 个不同的功能:

    • 服务器管理设置 IIS 可以接受的文件大小限制

    • 客户端管理设置浏览器可以发送的文件大小限制


    服务器文件限制由 web.config 中的 maxRequestLength 参数设置

     <httpRuntime requestValidationMode="2.0"  maxRequestLength="102400"/>
    

    这是一个 KByte 数值,因此 maxRequestLength="102400" 表示 100 MB 文件。


    浏览器文件限制由 .uploadify() javascript 初始化中的 sizeLimit 参数设置

    function uploadScript(sessionId, swfUrl, ascxUrl, cancelUrl) {
    $('input[type="file"]').each(function (i) {
        $(this).uploadify({
            'uploader': swfUrl,
            'script': ascxUrl,
            'scriptData': { 'sessionId': sessionId, 'clientId': $(this).attr("id") }, // $(this).closest("div").attr("id") 
            'cancelImg': cancelUrl,
            'auto': true,
            'multi': false,
            'fileDesc': 'Tutti i file',
            'fileExt': '*.*',
            'queueSizeLimit': 90,
            'sizeLimit': 100000000,
            'buttonText': 'Scegli file',
            'folder': '/uploads',
            'onAllComplete': function (event, queueID, fileObj, response, data) { }
        });
    });
    

    }

    sizeLimit 是一个字节值,因此要发送一个 100 MB 的文件,您必须考虑 100M = 1024*1024*100。

    【讨论】:

      【解决方案2】:

      ASP.NET 中的默认请求大小限制为 4MB。

      如果您想允许上传大于 4MB 的文件,请确保您在 web.config 中使用 &lt;httpRuntime&gt; 元素增加了请求大小的默认值:

      <system.web>
          <!-- 5MD (value is in KB here) -->
          <httpRuntime maxRequestLength="5120" />
          ...
      </system.web>
      

      如果您在 IIS7 上托管,您需要将 maxAllowedContentLength 设置为相同的值(以字节为单位):

      <system.webServer>
          <security>
              <requestFiltering>
                  <!-- 5MB (value is in bytes here) -->
                  <requestLimits maxAllowedContentLength="5242880" />
              </requestFiltering>
          </security>
      </system.webServer>
      

      就会话而言,您可能会发现following post 很有用。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      相关资源
      最近更新 更多