-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.php
More file actions
108 lines (89 loc) · 4.19 KB
/
Utils.php
File metadata and controls
108 lines (89 loc) · 4.19 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// Utility class to hold the constants and static functions
class Utils {
// TODO: Get your Client Id and Client Secret at https://dashboard.groupdocs.cloud (free registration is required)
static $ClientId = 'XXXX-XXXX-XXXX-XXXX';
static $ClientSecret = 'XXXXXXXXXXXXXXXX';
static $ApiBaseUrl = 'https://api.groupdocs.cloud';
static $MyStorage = 'First Storage';
// Getting the View API Instance
public static function GetViewApiInstance() {
// intializing the configuration
$configuration = new GroupDocs\Viewer\Configuration();
// Seting the configurations
$configuration->setAppSid(Utils::$ClientId);
$configuration->setAppKey(Utils::$ClientSecret);
$configuration->setApiBaseUrl(Utils::$ApiBaseUrl);
// Retrun the new ViewerAPI instance
return new GroupDocs\Viewer\ViewApi($configuration);
}
// Getting the Info API Instance
public static function GetInfoApiInstance() {
// intializing the configuration
$configuration = new GroupDocs\Viewer\Configuration();
// Seting the configurations
$configuration->setAppSid(Utils::$ClientId);
$configuration->setAppKey(Utils::$ClientSecret);
$configuration->setApiBaseUrl(Utils::$ApiBaseUrl);
// Retrun the new Info instance
return new GroupDocs\Viewer\InfoApi($configuration);
}
// Getting the Viewer StorageAPI API Instance
public static function GetStorageApiInstance() {
// intializing the configuration
$configuration = new GroupDocs\Viewer\Configuration();
// Seting the configurations
$configuration->setAppSid(Utils::$ClientId);
$configuration->setAppKey(Utils::$ClientSecret);
$configuration->setApiBaseUrl(Utils::$ApiBaseUrl);
// Retrun the new StorageApi instance
return new GroupDocs\Viewer\StorageApi($configuration);
}
// Getting the Viewer FolderAPI API Instance
public static function GetFolderApiInstance() {
// intializing the configuration
$configuration = new GroupDocs\Viewer\Configuration();
// Seting the configurations
$configuration->setAppSid(Utils::$ClientId);
$configuration->setAppKey(Utils::$ClientSecret);
$configuration->setApiBaseUrl(Utils::$ApiBaseUrl);
// Retrun the new FolderApi instance
return new GroupDocs\Viewer\FolderApi($configuration);
}
// Getting the Viewer FileAPI API Instance
public static function GetFileApiInstance() {
// intializing the configuration
$configuration = new GroupDocs\Viewer\Configuration();
// Seting the configurations
$configuration->setAppSid(Utils::$ClientId);
$configuration->setAppKey(Utils::$ClientSecret);
$configuration->setApiBaseUrl(Utils::$ApiBaseUrl);
// Retrun the new FileApi instance
return new GroupDocs\Viewer\FileApi($configuration);
}
// Uploading sample files into storage
public static function UploadResources() {
$storageApi = self::GetStorageApiInstance();
$fileApi = self::GetFileApiInstance();
$folder = realpath(__DIR__ . '\Resources');
$filePathInStorage = "";
$dir_iterator = new \RecursiveDirectoryIterator($folder);
$iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST);
echo 'Uploading file process executing...';
echo "\n";
foreach ($iterator as $file) {
if (!$file->isDir()) {
$filePath = $file->getPathName();
$filePathInStorage = str_replace($folder . '\\', "", $filePath);
echo $filePathInStorage;
echo "\n";
$isExistRequest = new \GroupDocs\Viewer\Model\Requests\objectExistsRequest($filePathInStorage);
$isExistResponse = $storageApi->objectExists($isExistRequest);
if (!$isExistResponse->getExists()) {
$putCreateRequest = new \GroupDocs\Viewer\Model\Requests\uploadFileRequest($filePathInStorage, $filePath);
$putCreateResponse = $fileApi->uploadFile($putCreateRequest);
}
}
}
}
}