AzureBlobModel.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using MessagePack;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.WindowsAzure.Storage.Table;
  4. using System;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.IO;
  7. using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
  8. namespace TEAMModelOS.SDK.Module.AzureBlob.Container
  9. {
  10. [MessagePackObject(keyAsPropertyName: true)]
  11. public class AzureBlobModel : TableEntity
  12. {
  13. public AzureBlobModel()
  14. {
  15. long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
  16. Timestamp = DateTimeHelper.ConvertToDateTime(time);
  17. }
  18. public AzureBlobModel(IFormFile f, string Container ,string groupName ,string newName)
  19. {
  20. long time= DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
  21. ContentType = f.ContentType;
  22. ContentDisposition = f.ContentDisposition;
  23. FileName = f.FileName;
  24. // Headers = f.Headers.Values;
  25. RealName = groupName + "/"+ newName;
  26. Folder = groupName;
  27. Length = f.Length;
  28. Name = f.Name;
  29. UploadTime = time;
  30. PartitionKey = Container;
  31. RowKey = Guid.NewGuid().ToString();
  32. Extension = f.FileName.Substring(f.FileName.LastIndexOf(".") + 1, (f.FileName.Length - f.FileName.LastIndexOf(".") - 1)); //扩展名
  33. Timestamp = DateTimeHelper.ConvertToDateTime(time);
  34. }
  35. public AzureBlobModel(FileInfo f, string Container, string groupName, string newName ,string contentType)
  36. {
  37. long time = DateTime.Now.ToUniversalTime().Ticks - 621355968000000000;
  38. ContentType = contentType;
  39. ContentDisposition = "form-data; name=\"file\"; filename=\"" + f.Name + "\"";
  40. FileName = f.Name;
  41. // Headers = f.Headers.Values;
  42. RealName = groupName + "/" + newName;
  43. Folder = groupName;
  44. Length = f.Length;
  45. Name = "file";
  46. UploadTime = time;
  47. PartitionKey = Container;
  48. RowKey = Guid.NewGuid().ToString();
  49. Extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1, (f.Name.Length - f.Name.LastIndexOf(".") - 1)); //扩展名
  50. Timestamp = DateTimeHelper.ConvertToDateTime(time);
  51. }
  52. [Required(ErrorMessage = "{0} 必须填写")]
  53. public string Folder { get; set; }
  54. [Required(ErrorMessage = "{0} 必须填写")]
  55. public string Sha1Code { get; set; }
  56. //
  57. // 摘要:
  58. // Gets the raw Content-Type header of the uploaded file.
  59. [Required(ErrorMessage = "{0} 必须填写")]
  60. public string BlobUrl { get; set; }
  61. //
  62. // 摘要:
  63. // Gets the raw Content-Type header of the uploaded file.
  64. [Required(ErrorMessage = "{0} 必须填写")]
  65. public string ContentType { get; set; }
  66. //
  67. // 摘要:
  68. // Gets the raw Content-Disposition header of the uploaded file.
  69. [Required(ErrorMessage = "{0} 必须填写")]
  70. public string ContentDisposition { get; set; }
  71. //
  72. // 摘要:
  73. // Gets the header dictionary of the uploaded file.
  74. // public IHeaderDictionary Headers { get; set; }
  75. //
  76. // 摘要:
  77. // Gets the file length in bytes.
  78. [Required(ErrorMessage = "{0} 必须填写")]
  79. public long Length { get; set; }
  80. //
  81. // 摘要:
  82. // Gets the form field name from the Content-Disposition header.
  83. [Required(ErrorMessage = "{0} 必须填写")]
  84. public string Name { get; set; }
  85. //
  86. // 摘要:
  87. // Gets the file name from the Content-Disposition header.
  88. [Required(ErrorMessage = "{0} 必须填写")]
  89. public string FileName { get; set; }
  90. [Required(ErrorMessage = "{0} 必须填写")]
  91. public string RealName { get; set; }
  92. //上传时间戳
  93. [Required(ErrorMessage = "{0} 必须填写")]
  94. public long UploadTime { get; set; }
  95. //上传扩展文件
  96. [Required(ErrorMessage = "{0} 必须填写")]
  97. public string Extension { get; set; }
  98. }
  99. }