Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
wai-blue committed Feb 17, 2025
1 parent 0e4b386 commit 0c69af1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clients/php/src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Loader {
public string $oauthEndpoint; // OAuth compatible endpoint of the IAM
public string $dtxsEndpoint; // DTXS endpoint

public string $documentsStorageFolder; // Folder where documents are stored

// HTTP client
public object $guzzle; // 3rd-party HTTP library
public object $lastResponse; // Calue of the last HTTP response
Expand Down Expand Up @@ -51,6 +53,8 @@ public function __construct(array $config)
$this->oauthEndpoint = $config['oauthEndpoint'] ?? "";
$this->dtxsEndpoint = $config['dtxsEndpoint'] ?? "";

$this->documentsStorageFolder = $config['documentsStorageFolder'] ?? '';

$this->database = '';

// initiate HTTP client
Expand Down
17 changes: 17 additions & 0 deletions clients/php/src/Traits/Documents.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ public function createDocument(string $folderUid, array $document): string
return (string) $res->getBody();
}

/**
* Shortcut to create a document from existing file.
*
* @param mixed $folderUid UID of the folder where is document located.
* @param mixed $uploadedFile Data about uploaded file, as it is stored in $_FILES.
* @return string DocumentUid in case of 200 success. Otherwise exception is thrown.
*/
public function createDocumentFromUploadedFile(string $folderUid, array $document, mixed $uploadedFile): string
{
$document['name'] = $uploadedFile['name'];
$document['content'] = date('Y-m-d H:i:s');
$res = $this->sendRequest("POST", "/database/{$this->database}/folder/{$folderUid}/document", $document, true);
$documentUid = (string) $res->getBody();
move_uploaded_file($uploadedFile['tmp_name'], $this->documentsStorageFolder . '/' . $documentUid . '/1');
return (string) $res->getBody();
}

/**
* Shortcut to update a document
*
Expand Down

0 comments on commit 0c69af1

Please # to comment.