POST /upload
The Upload Web API is used for the asynchronous upload of different media samples that are associated with a token and can later be used for various biometric operations.
When the API receives a sample, it automatically performs a quality-check. When the quality check succeeds, e.g. when exactly one face has been found in an image, the sample is placed in the BWS storage and associated with the token that has been used for the authorization of this API call.
Therefore we highly recommend to consider the following when uploading images:
This API call requires BWS Token Authentication, i.e. you have to provide an HTTP authorization header using the authorization method Bearer (for compatibility issues you can also use the JWT identifier) and a previously issued BWS token, which can be requested using the Token Web API.
up, down, left
and right
.
face
trait, audio data is associated
with the voice
trait. For example, the string "Face, Periocular" can be used to associate a single uploaded image
with the face
and the periocular
trait.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWgAAAHgCAAAAACtbai8AAAAK3RFWHRDcmVhdGlvbiBUaW1lAFNhdCwgMDYgSnVsIDIwMTMgMTI6MDU6MDIgR01Ur.....kmwH6EuNQiJQAAAABJRU5ErkJggg=="
The Upload Web API returns an UploadResult
object generated by a call to the BWS quality check method.
The returned object contains the flag Accepted that indicates whether the sample has passed the quality-check or not.
If the sample has not been accepted an appropriate Error is reported depending on the trait of the uploaded sample, e.g.
NoFaceFound
or MultipleFacesFound
for face samples or BadSignalQuality
or AudioSignalTooShort
for voice samples.
In any case some additional Warnings may be included in an array of Sample Error-codes as described in the quality check reference.
Accepted UploadResult Sample:
{
"Accepted": true,
"Warnings": [ "ImageTooSmall", "ImageTooBlurry" ]
}
Refused UploadResult Sample:
{
"Accepted": false,
"Error": "NoFaceFound",
}
UploadResult
object.
private static async Task<bool> UploadAsync(string bwsToken, string dataUrlImage)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bwsToken);
using (var content = new StringContent(dataUrlImage))
using (var response = await client.PostAsync(ENDPOINT + $"upload", content))
{
Console.Write("Uploading image... ");
if (response.StatusCode == HttpStatusCode.OK)
{
Console.WriteLine("succeeded");
string result = await response.Content.ReadAsStringAsync();
var json = JObject.Parse(result);
bool accepted = (bool)json["Accepted"];
string error = (string)json["Error"];
if (!string.IsNullOrEmpty(error)) { Console.WriteLine(error); }
var warnings = json["Warnings"];
return accepted;
}
Console.WriteLine(response.StatusCode.ToString());
return false;
}
}
}
const dataURL = canvas.toDataURL(); // or "bws.toGrayDataURL(canvas)" (see bws.capture.js)
jQuery.ajax({
url: "https://bws.bioid.com/extension/upload?" + jQuery.param({
"tag": "up"
}),
type: "POST",
headers: {
"Authorization": "Bearer " + token
},
data: dataURL,
}).done(function (data, textStatus, jqXHR) {
if (data.Accepted) {
console.log("upload succeeded", data.Warnings);
} else {
console.log("upload error", data.Error);
}
});
// using OkHttpClient from the OkHttp library
HttpUrl url = HttpUrl.parse("https://bws.bioid.com/extension/upload").newBuilder()
.addQueryParameter("trait", "face")
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer " + token)
.post(RequestBody.create(MediaType.parse("text/plain"), "data:image/png;base64," + Base64.getEncoder().encodeToString(getPngAsByteArray())))
.build();
OkHttpClient client = new OkHttpClient();
Response response = client.newCall(request).execute();
if (response.code() == 200) {
// using org.json.JSONObject from JSON-java library
JSONObject json = new JSONObject(response.body().string());
if (json.getBoolean("Accepted")) {
System.out.println("upload succeeded");
}
}
For a complete sample refer to the walkthrough.