HtexController.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using HTEXMarkWeb.Controllers;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing.Imaging;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. namespace HTEXWeb.Controllers
  13. {
  14. [ApiController]
  15. [Route("file")]
  16. public class HtexController: ControllerBase
  17. {
  18. private readonly IWebHostEnvironment webHostEnvironment;
  19. public HtexController(IWebHostEnvironment _webHostEnvironment) {
  20. webHostEnvironment = _webHostEnvironment;
  21. }
  22. //[HttpPost("upload")]
  23. //[RequestSizeLimit(102_400_000_00)] //最大10000m左右
  24. //public async Task<IActionResult> Generator([FromForm] IFormFile[] files)
  25. //{
  26. // string time = Guid.NewGuid().ToString("N");
  27. // string folder = webHostEnvironment.ContentRootPath+ "/Upload/" + time;
  28. // if (false == System.IO.Directory.Exists(folder))
  29. // {
  30. // //创建pic文件夹
  31. // System.IO.Directory.CreateDirectory(folder);
  32. // }
  33. // foreach (var file in files) {
  34. // var stream = System.IO.File.Create(folder+"/"+file.FileName);
  35. // await file.CopyToAsync(stream);
  36. // stream.Dispose();
  37. // }
  38. // return Ok();
  39. //}
  40. [HttpPost("upload")]
  41. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  42. public async Task<IActionResult> Upload([FromForm] IFormFile[] files)
  43. {
  44. string guid = Guid.NewGuid().ToString("N");
  45. string folder = webHostEnvironment.ContentRootPath + "/Upload/" + guid;
  46. if (false == System.IO.Directory.Exists(folder))
  47. {
  48. //创建pic文件夹
  49. System.IO.Directory.CreateDirectory(folder);
  50. }
  51. foreach (var file in files)
  52. {
  53. var stream = System.IO.File.Create(folder + "/" + file.FileName);
  54. await file.CopyToAsync(stream);
  55. stream.Dispose();
  56. }
  57. return Ok();
  58. }
  59. [HttpGet("qrcode")]
  60. public async Task<IActionResult> QRCode() {
  61. var img= ZxingCodeHelper.QRCode(JsonSerializer.Serialize(
  62. new {
  63. a = "15283771540",
  64. d = "https://cdhabook.teammodel.cn/mark",
  65. u = "/file/upload",
  66. t = "https://teammodelstorage.blob.core.chinacloudapi.cn/hiteachcc/huanghb8838/res/t/t.json"
  67. }),
  68. 500,500);
  69. MemoryStream Stream = new MemoryStream();
  70. img.Save(Stream, ImageFormat.Png);
  71. byte[] bytes = new byte[Stream.Length];
  72. Stream.Position = 0;
  73. Stream.Read(bytes, 0, (int)Stream.Length);
  74. Stream.Close();
  75. string qrcode = "data:image/png;base64," + System.Convert.ToBase64String(bytes);
  76. return Ok(qrcode);
  77. }
  78. }
  79. }