Describe the bug
I was trying to FormRecognizerClient.StartRecognizeCustomFormsFromUri() using a valid model id and SAS Uri, But getting BadRequest. But the same uri can be processed by form recognizer api.
Note that, Uri is valid and if I download data using WebClient and pass it as stream content to StartRecognizeCustomForms() then it works.
Expected behavior
It should return the processed result.
Actual behavior (include Exception or Stack Trace)
Service request failed.
Status: 400 (Bad Request)
Content:
{"error":{"code":"1003","message":"Parameter 'Source' is not a valid Uri."}}
Headers:
Transfer-Encoding: chunked
x-envoy-upstream-service-time: REDACTED
apim-request-id: REDACTED
Strict-Transport-Security: REDACTED
X-Content-Type-Options: REDACTED
Date: Fri, 24 Apr 2020 12:16:36 GMT
Content-Type: application/json; charset=utf-8
| StackTrace | " at Azure.AI.FormRecognizer.ServiceRestClient.AnalyzeWithCustomModel(Guid modelId, Nullable`1 includeTextDetails, SourcePath_internal fileStream, CancellationToken cancellationToken)\r\n at Azure.AI.FormRecognizer.FormRecognizerClient.StartRecognizeCustomFormsFromUri(String modelId, Uri formFileUri, RecognizeOptions recognizeOptions, CancellationToken cancellationToken)\r\n at FormV2Console.Program.
To Reproduce
Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)
Environment:
Hello, @SamratAlamgir. Thanks for bringing this issue to our attention.
I have a SAS URI that points to an image stored in a blob container, but I couldn't reproduce the behavior. There could be something very particular to yours that's making it fail. What's the format of the URI you are using? Mine is something like:
https://{storageaccount}.blob.core.windows.net/images/{filename}?sp={...}&st={...}&se={...}&spr={...}&sv={...}&sr={...}&sig={...}
Also, is your model trained with labels or with forms only? And in what OS are you running your code?
Additional information that could be helpful:
Did you happen to use other similar URIs and got the same result?
Did you happen to use other client methods with the same URI (StartRecognizeContentFromUri or StartRecognizeReceiptsFromUri)?
Hello @kinelski , Thanks for your prompt response.
https://{{storageaccount}}.blob.core.windows.net/kyc/01014d19-6884-4e11-9b60-ec4523dbd279/id%203.jpg?st=2020-04-24T12%3A26%3A44Z&se=2020-05-25T12%3A26%3A00Z&sp=rl&sv=2018-03-28&sr=b&sig=oc%2FPUDFKM3rXpUNEi0W8Ps%2F1b0dJf1HqPhmGwwPfQ24%3D
Not works for the same model and URI:
Response<IReadOnlyList<RecognizedForm>> forms = await client.StartRecognizeCustomFormsFromUri(modelId, new Uri(formUri)).WaitForCompletionAsync();
Works for the same model and URI:
WebClient wc = new WebClient();
byte[] imageBytes = wc.DownloadData(formUri);
var stream = new MemoryStream(imageBytes);
Response<IReadOnlyList<RecognizedForm>> forms = await client.StartRecognizeCustomForms(modelId, stream).WaitForCompletionAsync();
Also the same URI works for other client methods:
var result1 = await client.StartRecognizeContentFromUri(new Uri(formUri), null).WaitForCompletionAsync();
var result2 = await client.StartRecognizeReceiptsFromUri(new Uri(formUri), null).WaitForCompletionAsync();
@kinelski
I think I found a particular reason when it is not working. If the filename contains white space then it is not working. For example, id 3.jpg, id test.jpg not works but id_3.jpg and id_test.jpg works.
As this problem is occurring only for the StartRecognizeCustomFormsFromUri I hope we will get a fix for that.
@SamratAlamgir
Thanks once again for your feedback and for finding what's triggering the problem. I can confirm I'm able to reproduce it and it's in fact a bug.
I have labeled it as a bug and added it to one of our milestones. I'll post an update here and let you know once it's fixed.
I believe the issue is here:
Method System.Uri.ToString() returns the unescaped URL. The property System.Uri.AbsoluteUri should be used instead.
@SamratAlamgir Thanks once again for reporting this issue. Preview 3 will be released soon and will contain the fix (#12192).
You are welcome and thanks for letting me know about the update.
Most helpful comment
@SamratAlamgir
Thanks once again for your feedback and for finding what's triggering the problem. I can confirm I'm able to reproduce it and it's in fact a bug.
I have labeled it as a
bugand added it to one of our milestones. I'll post an update here and let you know once it's fixed.