Skip to content
kodinkat edited this page Apr 22, 2024 · 4 revisions

DT_Storage Class

Helper class used for interacting with main storage plugin functionality.

Check if DT_Storage class is enabled

DT_Storage::is_enabled()
  • Returns true, if a valid storage configuration has been created, enabled and selected as a default connection within D.T settings.

Fetch storage object file url

DT_Storage::get_file_url( string $key = '' )
  • key: For the given storage object key, a corresponding http url is created; with a 24 hours access window; otherwise, an empty string is returned.

Fetch storage object image thumbnail url

DT_Storage::get_thumbnail_url( string $key = '' )
  • key:
    • For all uploaded images, a corresponding thumbnail is generated and stored alongside original image. Similar to get_file_url(), this function returns a valid http url, with a 24 hours access restriction.
    • Alternatively, an empty string is returned if unable to generate thumbnail url.

Upload file

DT_Storage::upload_file( string $key_prefix = '', array $upload = [], string $existing_key = '', array $args = [] )
  • key_prefix:

    • Key prefix to be used when storing uploaded file object.
    • It is good practice to use context based prefixes. For example, a users prefix, will typically be used for all user related uploads, such as the storing of profile pictures.
  • upload:

    • $_FILES array of file to be uploaded and stored; with the following structure:
    (
      [name] => image.png
      [full_path] => image.png
      [type] => image/png
      [tmp_name] => /private/var/tmp/phpZRYM5J
      [error] => 0
      [size] => 49807
    )
  • existing_key:

    • If object file has been previously stored and the current upload request, is an update; then reusing the same key, will force an overwrite within the backend storage service.
  • response:

    • False will be returned, in the event of any upload failures; otherwise the following array structure is provided, with uploaded key references.
    (
      [uploaded_key] => /users/H8FG0f5WLKxEo8n64GDP2Buc.png
      [uploaded_thumbnail_key] => /users/H8FG0f5WLKxEo8n64GDP2Buc_thumbnail.png
    )

Validate connection details

DT_Storage::validate_connection_details( $connection_type_api = '', $details = [] )
  • connection_type_api:

    • Specify backend storage service api to be used. Currently s3 is the only supported api.
  • details:

    • API specific connection details to be validated. So, in the case of s3, the following array structure is expected:
    (
      [access_key] => 003872fed596de............
      [secret_access_key] => K003HcPupRkLrDL8...............
      [region] => eu-central-003
      [bucket] => dt-objects-bucket
      [endpoint] => https://s3.eu-central-003.backblazeb2.com
    )
  • response:

    • True is returned following a successful validation.