Mathematica Asked on March 7, 2021
I have a simple API that takes a recipe and returns the list of ingredients:
api = CloudDeploy[APIFunction[{"img"->"Image"},
(ResourceFunction["DeleteFailures"]@Map[Function[w, Interpreter["FoodType"][w]], Flatten @ TextRecognize[#img, "Word"]])&
], Permissions->"Public", IncludeDefinitions->True]
So here’s the example I’m trying to make work:
recipe = CloudGet@"https://www.wolframcloud.com/obj/fe25d585-acc3-4931-9223-da5ee1dce6bd";
The function inside the API works just fine locally (without the APIFunction & CloudDeploy) as you can see:
AbsoluteTiming[Function[{img}, ResourceFunction["DeleteFailures"]@Map[Function[w,
Interpreter["FoodType"][w]], Flatten@TextRecognize[img, "Word"]]][recipe]]
But when deployed as an API in the Wolfram Cloud, it refuses to return anything, how can I get this to work?
What I’ve Tried
A simple POST request with URLExecute
gives a 408 error:
AbsoluteTiming[URLExecute[api, <|"img"->recipe|>, TimeConstraint->[Infinity]]]
Another attempt with the obsolete-but-still-super-useful URLFetch
with multi-part data gives a 503 error (btw, does anyone know how to accomplish this without using an obsolete symbol?):
AbsoluteTiming[URLFetch[api, "Method" -> "POST", "MultipartElements" -> {{"img", "image/jpeg"} -> ExportString[recipe, "JPEG"]}]]
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP