• Developer guides

File storage

The Document storage method uploads files to several different servers to ensure redundancy and speed. This also means that a file has several URLs. That is why the Document Storage API returns a document ID, with which you can request the document URL. You should save the document ID, as it is the only way to get the right URL for the file. Look at the examples to get a better understanding of how this works.

You can upload documents using the method upload(), which takes a single argument:

  • string $input_name – the name of the file input, i.e. myfile for <input type="file" name="myfile" />.

Uploading a document

Example HTML

<form action="<?=$this->module->request_url;?>" method="post" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="name">

    <input type="submit" value="Upload" name="submit">
</form>

Example PHP

 <?php

// Check if it is a POST request
if ($this->request->is('post')) {

  // Upload from URL
  $document = $this->storage->upload('file');

  if (!$document->error) {

    // We got the Document ID, so let's save it as a key-value object.
    $this->storage->keyvalue('myFileID', $document->id);

    // The document also contains the current URL
    echo ('Temporary URL: ' . $document->url);
  } else {
    echo ('Something went wrong.');
  }

}

Retrieving file metadata