| | |
| | | using System.Globalization; |
| | | using System.Security.Policy; |
| | | using TencentCloud.Ocr.V20181119.Models; |
| | | using TencentCloud.Teo.V20220901.Models; |
| | | using Task = System.Threading.Tasks.Task; |
| | | namespace EzUpFile |
| | | { |
| | | /// <summary> |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | public async Task<(BizLicenseOCRResponse, string)> UpBizLicense() |
| | | { |
| | | try |
| | | { |
| | | |
| | | var maxSize = 1024 * 1024 * 5; //上传大小5M |
| | | |
| | | var FileData = _request?.Form?.Files["file"]; |
| | | |
| | | if (FileData.Length > maxSize) |
| | | { |
| | | throw Oops.Oh(" 上传文件不可超出500K"); |
| | | } |
| | | |
| | | |
| | | //处理图形 |
| | | // var FileData = Request.Form.Files[0]; |
| | | |
| | | Image oimage = Image.FromStream(FileData.OpenReadStream()); |
| | | if (oimage == null) |
| | | { |
| | | throw Oops.Oh(" 上传失败"); |
| | | } |
| | | |
| | | MemoryStream ms = new MemoryStream(); |
| | | if (oimage.Width > 600) |
| | | |
| | | { |
| | | if (oimage.Width > oimage.Height) |
| | | oimage.GetThumbnailImage(600, 400, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Png); |
| | | else |
| | | oimage.GetThumbnailImage(400, 600, null, IntPtr.Zero).Save(ms, System.Drawing.Imaging.ImageFormat.Png); |
| | | } |
| | | else |
| | | oimage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); |
| | | ms.Position = 0; |
| | | |
| | | var arr = ms.ToArray(); |
| | | string img64 = Convert.ToBase64String(arr); |
| | | |
| | | BizLicenseOCRResponse info = null; |
| | | string url = ""; |
| | | |
| | | try |
| | | { |
| | | info = _tcs.BizLicenseOCR(img64); |
| | | |
| | | url = await UploadFilesFByBase64(img64); |
| | | |
| | | return (info, url); |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | |
| | | throw Oops.Oh(e.Message); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | |
| | | throw Oops.Oh(e.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |