# 5.3 Prepare Document to be Signed
# Use cases
Prepares the given document in order to be signed from user with his private signing key linked to the public one inside the certificate.
# Dart
- Plugin http
- Plugin http_parser
# Kotlin
- Library OkHttp
# Background
From Wikipedia:
In mathematics and computing, hexadecimal (also base 16, or hex) is a positional system that represents numbers using a base of 16.
# Step by step sequence
- Get the certificate;
- Get the document;
- Build the request;
- Finally, send the request.
# Code Examples
Here's an example of the implemetation in all the available languages.
# Dart
var certificate = File('/pems/certificate.pem');
var document = File('/xmls/document.xml');
var uri = Uri.parse(
'https://api.commercio.network/sign');
var request = new http.MultipartRequest('POST', uri);
request.files.add(
await http.MultipartFile.fromPath(
'certificate',
certificate.path,
contentType: new MediaType('application', 'x-tar'),
),
);
request.files.add(
await http.MultipartFile.fromPath(
'document',
document.path,
contentType: new MediaType('application', 'x-tar'),
),
);
http.StreamedResponse response = await request.send();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Kotlin
val requestBody: RequestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart(
"certificate", "certificate.pem",
File("/pems/certificate.pem")
.asRequestBody("application/octet-stream".toMediaTypeOrNull())
)
.addFormDataPart(
"document", "document.xml",
File("/xmls/document.xml")
.asRequestBody("application/octet-stream".toMediaTypeOrNull())
)
.build()
val okHttpClient = OkHttpClient()
val request = Request.Builder()
.method("POST", requestBody)
.url("https://api.commercio.network/sign")
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
// Handle this
}
override fun onResponse(call: Call, response: Response) {
if (!response.isSuccessful) {
// Handle the error
}
// Upload successful
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30