public async Task <HttpResponseMessage> ProcessPhotoPostAsync(string personGroupId, string personId) { InitEnvironment(); #region Step1-Step2. 첨부된 파일을 Web App의 Map Path에 복사하고, 이를 Blob Container에 업로드 MultipartFormdataStreamBlobUploader multipartFormdataStreamBlobUploader = new MultipartFormdataStreamBlobUploader(provider, storageAccount, container); listUrlBlob = await multipartFormdataStreamBlobUploader.UploadAttachedFileToBlobContainer(this.Request, blobPrefixString); #endregion // 변수 만들기 PhotoUploadedResult // try 안에서 할당 // 스텝4에서 활용 PhotoUploadedResult photoUploadedResult; HttpResponseMessage message; #region Step3. 저장한 blob 위치를 json body로 반환 try { if (listUrlBlob.Count > 0) { photoUploadedResult = new PhotoUploadedResult(personGroupId, personId, listUrlBlob[0].url); message = Request.CreateResponse(HttpStatusCode.OK, photoUploadedResult); } else { photoUploadedResult = new PhotoUploadedResult(personGroupId, personId, ""); message = Request.CreateResponse(HttpStatusCode.OK, photoUploadedResult); } } catch (Exception e) { Trace.WriteLine("Exception occurred while reading returningBlobUrl."); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } #endregion #region Step4. Queue에도 전송 try { CloudQueueMessage messageQueue = new CloudQueueMessage(JsonConvert.SerializeObject(photoUploadedResult)); queue.AddMessage(messageQueue); Trace.WriteLine("BlobInQueue: " + JsonConvert.SerializeObject(photoUploadedResult)); } catch (Exception e) { Trace.WriteLine("Exception occurred while sending message to queue."); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } return(message); #endregion }
public async Task <HttpResponseMessage> ProcessIdcardPostAsync() { InitEnvironment(); #region Step1-Step2. 첨부된 파일을 Web App의 Map Path에 복사하고, 이를 Blob Container에 업로드 MultipartFormdataStreamBlobUploader multipartFormdataStreamBlobUploader = new MultipartFormdataStreamBlobUploader(provider, storageAccount, container); listUrlBlob = await multipartFormdataStreamBlobUploader.UploadAttachedFileToBlobContainer(this.Request, blobPrefixString); #endregion #region Step3. 저장한 blob 위치를 인지서비스에 전달하여 OCR 및 Face 정보 추출 try { foreach (UrlBlob urlBlob in listUrlBlob) { //OCR 호출 List <string> contentsOcr = await CognitiveServicesCallHelper.CognitiveServicePostAsync( CloudConfigurationManager.GetSetting("CognitiveServicesKeyVision"), "https://eastasia.api.cognitive.microsoft.com/vision/v1.0/ocr?language=ko&detectOrientation=true", urlBlob.url); //OCR 결과를 건별로 Queue에 넣음, trace 표시 foreach (string content in contentsOcr) { CloudQueueMessage message = new CloudQueueMessage(content); queue.AddMessage(message); Trace.WriteLine("OCR: " + content); } //Face Detection 호출 List <string> contentsFace = await CognitiveServicesCallHelper.CognitiveServicePostAsync( CloudConfigurationManager.GetSetting("CognitiveServicesKeyVision"), "https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceAttributes=age,gender,headPose,glasses,accessories", urlBlob.url); //Face 결과를 trace 표시 foreach (string content in contentsFace) { List <FaceDetectResult> faceDetectResults = JsonConvert.DeserializeObject <List <FaceDetectResult> >(content); if (faceDetectResults.Count > 0) { Trace.WriteLine("Face: " + content); Trace.WriteLine("FaceId: " + faceDetectResults[0].faceId); HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.OK, new JsonFaceId(faceDetectResults[0].faceId)); return(message); } } } // return empty FaceId if no faces were found. return(Request.CreateResponse(HttpStatusCode.OK, new JsonFaceId(""))); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } #endregion }