Web Upload API

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.

Important Note: The upload might take a long time if the user has a slow internet connection! Therefore we highly recommend to consider the following when uploading images:

  • Use a lossless compression algorithm for the image if possible.
  • Use an aspect ratio of 3 : 4, i.e. we recommend to crop the captured images to be higher than wide as BWS internally works on 3 : 4 images. (Example: With a 640 x 480 camera, if you remove areas to the left and the right so that you get a 360 x 480 image, you reduce the upload size by nearly 50%.) Note that if you crop the image, ensure that the head of the person is within the cropped area.
  • We recommend an image height of 480 pixel for enrollment and an image height of at least 320 pixel for verification (using an image size of 240 x 320 reduces the upload size again by more than 50%). Note when using those low resolutions, ensure that the users face covers most of the image.

Request Information

Parameters

tag An optional tag that describes some kind of demand or characteristics of the sample. For example: if a liveness detection with challenge-response shall be performed on a face or periocular sample, the expected head movement direction can be specified with this tag using one or more of the values updownleft and right.
index An optional index within a sequence of uploaded samples. If given it is only used to sort the uploaded samples in the order they are intended to be (important for challenge-response).
trait Optionally overwrite of default trait-handling: images are associated with the 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.
dataURL

A single media sample, encoded into a Data-URL using the data URI scheme as described in RFC 2397 (see also at Wikipedia).

Send this parameter in the request body.

Request Body Format

Sample Data-Url
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWgAAAHgCAAAAACtbai8AAAAK3RFWHRDcmVhdGlvbiBUaW1lAFNhdCwgMDYgSnVsIDIwMTMgMTI6MDU6MDIgR01Ur.....kmwH6EuNQiJQAAAABJRU5ErkJggg=="

Authentication

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.

Response Information

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.

Response Body Format

application/json, text/json
Accepted UploadResult Sample:
{
  "Accepted": true, 
  "Warnings": [ "ImageTooSmall", "ImageTooBlurry" ]
}


Refused UploadResult Sample:
{
  "Accepted": false, 
  "Error": "NoFaceFound",
}

Response HTTP Status Codes

Return values of API calls are standard HTTP status codes. With the success code (200) you receive the issued BWS token in the body text. With error codes a Message field within the body text describing the error is returned. The most commonly return codes are:

200 OK The response body contains the UploadResult object.
400 Bad Request Invalid sample data has been uploaded or the sample format is unsupported.
401 Unauthorized No or an invalid authentication header has been specified. This call requires JWT Bearer Token Authentication. If a BWS token has been passed, this error typically indicates that the token has expired.
500 Internal Server Error A server side exception occurred.

Sample Code

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    using (var stream = file.OpenRead())
    {
        var buffer = new byte[file.Length];
        await stream.ReadAsync(buffer, 0, buffer.Length);
        using (var content = new StringContent(ENCODING_LEAD + Convert.ToBase64String(buffer)))
        using (var response = await client.PostAsync(ENDPOINT + $"upload", content))
        using (var responseStream = await response.Content.ReadAsStreamAsync())
        {
            return JsonTypes.ParseUpload(responseStream);
        }
    }
}

For a complete sample refer to the walk-through .

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);
  }
});

See also: method upload in bws.capture.js, which is part of the BWS unified user interface.

// 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");
    }
}