12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using HTEXMarkWeb.Controllers;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
-
- using System;
- using System.Collections.Generic;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text.Json;
- using System.Threading.Tasks;
- namespace HTEXWeb.Controllers
- {
- [ApiController]
- [Route("file")]
- public class HtexController: ControllerBase
- {
- private readonly IWebHostEnvironment webHostEnvironment;
- public HtexController(IWebHostEnvironment _webHostEnvironment) {
- webHostEnvironment = _webHostEnvironment;
- }
- //[HttpPost("upload")]
- //[RequestSizeLimit(102_400_000_00)] //最大10000m左右
- //public async Task<IActionResult> Generator([FromForm] IFormFile[] files)
- //{
- // string time = Guid.NewGuid().ToString("N");
- // string folder = webHostEnvironment.ContentRootPath+ "/Upload/" + time;
- // if (false == System.IO.Directory.Exists(folder))
- // {
- // //创建pic文件夹
- // System.IO.Directory.CreateDirectory(folder);
- // }
- // foreach (var file in files) {
- // var stream = System.IO.File.Create(folder+"/"+file.FileName);
- // await file.CopyToAsync(stream);
- // stream.Dispose();
- // }
- // return Ok();
- //}
- [HttpPost("upload")]
- [RequestSizeLimit(102_400_000_00)] //最大10000m左右
- public async Task<IActionResult> Upload([FromForm] IFormFile[] files)
- {
- string guid = Guid.NewGuid().ToString("N");
- string folder = webHostEnvironment.ContentRootPath + "/Upload/" + guid;
- if (false == System.IO.Directory.Exists(folder))
- {
- //创建pic文件夹
- System.IO.Directory.CreateDirectory(folder);
- }
- foreach (var file in files)
- {
- var stream = System.IO.File.Create(folder + "/" + file.FileName);
- await file.CopyToAsync(stream);
- stream.Dispose();
- }
- return Ok();
- }
- [HttpGet("qrcode")]
- public async Task<IActionResult> QRCode() {
- var img= ZxingCodeHelper.QRCode(JsonSerializer.Serialize(
- new {
- a = "15283771540",
- d = "https://cdhabook.teammodel.cn/mark",
- u = "/file/upload",
- t = "https://teammodelstorage.blob.core.chinacloudapi.cn/hiteachcc/huanghb8838/res/t/t.json"
- }),
- 500,500);
- MemoryStream Stream = new MemoryStream();
- img.Save(Stream, ImageFormat.Png);
- byte[] bytes = new byte[Stream.Length];
- Stream.Position = 0;
- Stream.Read(bytes, 0, (int)Stream.Length);
- Stream.Close();
- string qrcode = "data:image/png;base64," + System.Convert.ToBase64String(bytes);
- return Ok(qrcode);
- }
- }
- }
|