Example of AuthenticateDocument Network Call in Document Scan SDK for Android
The AuthenticateDocument endpoint takes multipart/form-data in the request. If you’re not using a networking library, it may be a little confusing to write. Below is some basic code that will get you going.
Note: This is not production-ready code. Please make the necessary modifications to insert this code in your app.
Copy
private fun createIdDocumentSingle(context: Context,
token: String,
key: String,
frontDocumentResult: DSResult,
backDocumentResult: DSResult?,
documentType: DocumentType,
autoCrop: Boolean): Single<DocumentScanResponse> {
val frontImage = frontDocumentResult.image
val frontImageBody = createMultipartBody("Front", frontImage)
if (frontImageBody == null) {
Log.d(this.toString(), "No front image data found in the document scan data")
throw createError(context.getString(R.string.front_image_data_missing))
}
val frontFlash = frontDocumentResult.flashImage
val backImage = backDocumentResult?.image
val backFlashImage = backDocumentResult?.flashImage
val transactionId = documentTransactionId
val submitDocument = if (transactionId == null) {
YourNetworkManager.yourAPIService.submitDocument(
token,
key,
documentType.rawType,
autoCrop,
true,
documentType.orientation,
ApplicationSettings.deviceDetails,
frontImageBody,
(backImage != null) ? createMultipartBody("Back", backImage) : null,
(frontFlash != null) ? createMultipartBody("FrontFlash", frontFlash) : null,
(backFlashImage != null) ? createMultipartBody("BackFlash", backFlashImage): null
)
} else {
YourNetworkManager.yourAPIService.submitRescanDocument(
token,
key,
documentType.rawType,
autoCrop, true,
documentType.orientation,
ApplicationSettings.deviceDetails,
transactionId,
frontImageBody,
(backImage != null) ? createMultipartBody("Back", backImage) : null,
(frontFlash != null) ? createMultipartBody("FrontFlash", frontFlash) : null,
(backFlashImage != null) ? createMultipartBody("BackFlash", backFlashImage): null
)
}
return submitDocument
.subscribeOn(schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}