Просмотр исходного кода

redact_info_extract 新增 md5 參數

ChingYi 8 месяцев назад
Родитель
Сommit
2003335d6d
1 измененных файлов с 17 добавлено и 6 удалено
  1. 17 6
      DocAI/DocAI.cs

+ 17 - 6
DocAI/DocAI.cs

@@ -56,8 +56,13 @@ namespace KdanCommon.DocAI
         public async Task<VerifyUserResponse> VerifyUser()
         {
             VerifyUserResponse response = null;
-            var result = await _httpClient.PostAsync(_verifyUserUri, new MultipartFormDataContent());
-            if (result.StatusCode == System.Net.HttpStatusCode.OK)
+            HttpResponseMessage result = null;
+            try
+            {
+                result = await _httpClient.PostAsync(_verifyUserUri, new MultipartFormDataContent());
+            }
+            catch { }
+            if (result != null && result.StatusCode == System.Net.HttpStatusCode.OK)
             {
                 var jsonString = await result.Content.ReadAsStringAsync();
                 response = JsonTool.DeserializeJSON<VerifyUserResponse>(jsonString);
@@ -65,7 +70,7 @@ namespace KdanCommon.DocAI
             return response;
         }
 
-        public async Task<RedactInfoExtractResponse> RedactInfoExtract(StorageFile file, string redactInfo, string docType, string pageRange = null, string redactCustomInfo = null)
+        public async Task<RedactInfoExtractResponse> RedactInfoExtract(StorageFile file, string fileName, string md5, string redactInfo, string docType, string pageRange = null, string redactCustomInfo = null)
         {
             RedactInfoExtractResponse response = null;
             using (var fileStream = await file.OpenStreamForReadAsync())
@@ -74,8 +79,9 @@ namespace KdanCommon.DocAI
                 var streamContent = new StreamContent(fileStream);
                 streamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data");
                 streamContent.Headers.ContentDisposition.Name = "redact_file";
-                streamContent.Headers.ContentDisposition.FileName = file.Name;
+                streamContent.Headers.ContentDisposition.FileName = fileName;
                 content.Add(streamContent);
+                content.Add(CreateStringContent(md5, "md5"));
                 content.Add(CreateStringContent(redactInfo, "redact_info"));
                 content.Add(CreateStringContent(_appName, "app_name"));
                 content.Add(CreateStringContent(_appVersion, "app_version"));
@@ -85,8 +91,13 @@ namespace KdanCommon.DocAI
                     content.Add(CreateStringContent(redactCustomInfo, "redact_custom_info"));
                 if (!string.IsNullOrEmpty(pageRange))
                     content.Add(CreateStringContent(pageRange, "page_range"));
-                var result = await _httpClient.PostAsync(_redactInfoExtractUri, content);
-                if (result.StatusCode == System.Net.HttpStatusCode.OK)
+                HttpResponseMessage result = null;
+                try
+                {
+                    result = await _httpClient.PostAsync(_redactInfoExtractUri, content);
+                }
+                catch { }
+                if (result != null && result.StatusCode == System.Net.HttpStatusCode.OK)
                 {
                     var jsonString = await result.Content.ReadAsStringAsync();
                     response = JsonTool.DeserializeJSON<RedactInfoExtractResponse>(jsonString);