-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupload-file.php
74 lines (63 loc) · 1.78 KB
/
upload-file.php
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/lib.php';
/**
*
* PARAMETERS
*
*/
/**
* File name of document you want to sign.
*/
$file['name'] = 'test.pdf';
/**
* HTTP URL where the file is stored.
* Documents Gateway will download the file from given resource URL. Ensure that file URL is accessible from internet.
* Base64 encoded file[content] could be used instead of file[url].
*/
$file['url'] = 'https://gateway-sandbox.dokobit.com/sc/test.pdf';
/**
* SHA256 file hash. SHA1 is supported, but not recommended.
*/
$file['digest'] = '6256a099cd2a3d3606acc86e7eacbdcf4cd067db3a1d46930d77886d96fd226e';
/**
*
* MAKING API REQUESTS
*
*/
/**
* Upload file
*/
$action = 'file/upload';
$uploadResponse = request(getApiUrlByAction($action), [
'file' => $file
], REQUEST_POST);
if ($uploadResponse['status'] != 'ok') {
echo "File could not be uploaded.
Please ensure that file URL is accessible from the internet." . PHP_EOL;
exit;
}
/**
* Check file status
*/
$action = 'file/upload/status/' . $uploadResponse['token'];
$statusResponse = '';
while ($statusResponse === '' || $statusResponse['status'] == 'pending') {
$statusResponse = request(getApiUrlByAction($action), [
'token' => $uploadResponse['token']
], REQUEST_GET);
sleep(2);
}
if (empty($statusResponse) || $statusResponse['status'] != 'uploaded') {
echo "Documents Gateway could not download the file.
Please ensure that file URL is accessible from the internet."
. PHP_EOL;
exit;
}
/**
* Success. Signing can be created using file token.
*/
echo "File has been successfully uploaded." . PHP_EOL;
echo "File token is: " . PHP_EOL . PHP_EOL;
echo " " . $uploadResponse['token'] . PHP_EOL . PHP_EOL;
echo "Use this token to create signing." . PHP_EOL;