JS
const request = require('superagent');
async function readImage(imagePath,ocrUrl) {
return request
.post(ocrUrl)
.attach('image', imagePath)
.then((res) => {
return res.body.results;
});
}
Java
public String readImage(byte[] imageBytes, String fileName, String ocrUrl) throws IOException {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(ocrUrl);
ByteArrayBody byteArrayBody = new ByteArrayBody(imageBytes, ContentType.APPLICATION_OCTET_STREAM, fileName);
HttpEntity entity = MultipartEntityBuilder.create()
.addPart("image", byteArrayBody)
.build();
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String result = EntityUtils.toString(responseEntity);
return result;
}
C#/Net
public static void Classify(byte[] imageBytes, string fileName, string ocrUrl)
{
var formData = new MultipartFormDataContent();
formData.Add(new ByteArrayContent(imageBytes), "image", fileName);
var httpclient = new HttpClient();
var signatureResult = httpclient.PostAsync(ocrUrl, formData).Result.Content.ReadAsStringAsync().Result;
}