IFormFile.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //------------------------------------------------------------------------------
  2. // 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
  3. // 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
  4. // CSDN博客:https://blog.csdn.net/qq_40374647
  5. // 哔哩哔哩视频:https://space.bilibili.com/94253567
  6. // Gitee源代码仓库:https://gitee.com/RRQM_Home
  7. // Github源代码仓库:https://github.com/RRQM
  8. // API首页:https://www.yuque.com/rrqm/touchsocket/index
  9. // 交流QQ群:234762506
  10. // 感谢您的下载和使用
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. using System.Collections.Specialized;
  14. namespace TouchSocket.Http
  15. {
  16. /// <summary>
  17. /// 表单文件
  18. /// </summary>
  19. public interface IFormFile
  20. {
  21. /// <summary>
  22. /// 获取Content-Disposition
  23. /// </summary>
  24. string ContentDisposition { get; }
  25. /// <summary>
  26. /// 获取Content-Type
  27. /// </summary>
  28. string ContentType { get; }
  29. /// <summary>
  30. /// 实际的数据
  31. /// </summary>
  32. public byte[] Data { get; }
  33. /// <summary>
  34. /// 数据对
  35. /// </summary>
  36. public NameValueCollection DataPair { get; }
  37. /// <summary>
  38. /// 获取file name
  39. /// </summary>
  40. string FileName { get; }
  41. /// <summary>
  42. /// 文件长度。在数据接收完成之前,该值为-1;
  43. /// </summary>
  44. long Length { get; }
  45. /// <summary>
  46. /// 获取name字段
  47. /// </summary>
  48. string Name { get; }
  49. ///// <summary>
  50. ///// 读取文件数据 //太麻烦先不实现
  51. ///// </summary>
  52. //public int Read(byte[] buffer, int offset, int count);
  53. }
  54. internal class InternalFormFile : IFormFile
  55. {
  56. public string ContentDisposition => DataPair["Content-Disposition"];
  57. public string ContentType => DataPair["Content-Type"];
  58. public byte[] Data { get; set; }
  59. public NameValueCollection DataPair { get; set; }
  60. public string FileName => DataPair["filename"];
  61. public long Length => Data == null ? 0 : Data.Length;
  62. public string Name => DataPair["name"];
  63. //public int Read(byte[] buffer, int offset, int count)
  64. //{
  65. // return this.ReadAction(buffer, offset, count);
  66. //}
  67. //public Func<byte[], int, int, int> ReadAction { get; set; }
  68. }
  69. }