下载超过100M的文件

/// <summary>
 /// download file
 /// </summary>
 public class FileDownload:System.Web.UI.Page
 {
  /// <summary>
  /// download file
  /// </summary>
  /// <param name="FilePath">file path</param>
  /// <param name="FileName">file name</param>
  public static void Download(string FilePath,string FileName)
  {
   Stream iStream = null;
   // Buffer to read 10K bytes in chunk:
   byte [] buffer = new byte [10000];

   // Length of the file:
   int length;

   //total bytes to read
   long dataToRead;

   try
   {
    // Open the file.
    iStream = new FileStream(FilePath,FileMode.Open,FileAccess.Read,FileShare.Read);

    // Total bytes to read:
    dataToRead = iStream.Length;

    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName));

    // Read the bytes.
    while (dataToRead > 0)
    {
     // Verify that the client is connected.
     if (HttpContext.Current.Response.IsClientConnected)
     {
      // Read the data in buffer.
      length = iStream.Read(buffer, 0, 10000);
     
      // Write the data to the current output stream.
      HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);
     
      // Flush the data to the HTML output.
      HttpContext.Current.Response.Flush();
     
      buffer= new Byte[10000];
      dataToRead = dataToRead - length;
     }
     else
     {
      //prevent infinite loop if user disconnects
      dataToRead = -1;
     }
    }
   }
   catch(Exception ex)
   {
    // Trap the error, if any.
    Console.Write("Error:" + ex.Message.ToString());
   }
   finally
   {
    if (iStream != null)
    {
     //Close the file.
     iStream.Close();
    }
   }
  }
 }

在Gitee上上传超过100M的大文件,可以使用Gitee的Git LFS(Large File Storage)功能。Git LFS是一个Git扩展,它允许你将大文件存储在Git仓库之外,而是将它们存储在一个单独的存储库中。这样,你就可以将大文件的指针添加到Git仓库中,而不会使仓库变得过大。 以下是在Gitee上使用Git LFS上传大文件的步骤: 1. 安装Git LFS客户端:在你的本地电脑上安装Git LFS客户端。你可以在Git LFS官方网站上下载安装包。 2. 在Gitee上创建LFS存储库:在Gitee上创建一个LFS存储库,用于存储大文件。你可以在Gitee的仓库设置中启用Git LFS功能。 3. 初始化LFS仓库:在本地电脑上,进入你的Git仓库目录,并运行以下命令来初始化LFS仓库: ``` git lfs install ``` 4. 添加大文件:将大文件添加到Git仓库中。你可以使用以下命令: ``` git lfs track "path/to/large/file" ``` 这将为大文件创建一个指针,并将其添加到.gitattributes文件中。 5. 提交并推送:将修改提交到Git仓库,并将指针推送到Gitee的LFS存储库中。你可以使用以下命令: ``` git add . git commit -m "Add large file" git push origin master ``` 这将提交修改,并将指针推送到Gitee的LFS存储库中。 在使用Git LFS时,你需要注意以下几点: 1. 每个Gitee用户可以创建一个LFS存储库,用于存储大文件。如果你需要存储更多的大文件,你可以购买额外的LFS存储空间。 2. Git LFS仅适用于二进制文件,如图像、视频、音频等。对于文本文件,应使用Git的标准做法。 3. 在使用Git LFS上传大文件时,需要确保你的网络连接稳定,以避免上传失败或数据损坏的情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值