TINY BLOG > Important changes to Tiny Cloud pricing > Find out more
Cart Checkout Return to Website

Tiny Drive Standalone API

Description of the Tiny Drive standalone api

Contribute to this page

Tiny Drive can be used as a generic file manager separate from TinyMCE this is referred to as standalone mode.

Loading the standalone API script

In order to use Tiny Drive in standalone mode you will need to add a script to your page with your API key as part of the URL. The URL is in the following format:

https://cdn.tiny.cloud/1/<your api key>/tinydrive/stable/tinydrive.min.js

Example

<script src="https://cdn.tiny.cloud/1/<your api key>/tinydrive/stable/tinydrive.min.js" referrerpolicy="origin"></script>
<script>
tinydrive.pick({
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});
</script>

tinydrive.pick

The tinydrive.pick method enables you to pick files from Tiny Drive and get the meta data of those files returned in a promise. For a complete list of available settings to pass into this method check the Picker settings section in this page.

File Picker Result Format

The tinydrive.pick method will return a promise with object that has a files property. This files property is an array of files with the following properties.

name

The name of the selected file for example my.jpg.

size

The size in bytes of the selected file.

url

The URL for the selected file would be in the following format: https://drive.tiny.cloud/1/<your api key>/<file uuid>

mdate

The modification date for the file in ISO 8601 format for example 2019-02-24T15:00:00Z

Demo

tinydrive.browse

The tinydrive.browse method enables you to browse your files stored in Tiny Drive but without the possibility to pick them to be inserted. This might be useful if you want to use Tiny Drive as a generic file manager. It returns a promise but the promise will only resolve when the Tiny Drive dialog is closed by using the close button. For a complete list of available settings to pass in to this method check the Picker settings section in this page.

Demo

tinydrive.upload

The tinydrive.upload method enables directly upload blobs to your Tiny Drive storage. This can be useful when you want to store a file generated by your app.

Demo

0%

tinydrive.start

Start is similar to pick and browse, the main difference is that method doesn’t have a way of closing the dialog. This can be useful when you want to lauch Tiny Drive from an url where there is no application to insert the files into. This might be useful when you want to launch Tiny Drive from an url but not part of a bigger application. For a complete list of available settings to pass in to this method check the Picker settings section in this page.

Example

tinydrive.start({
  token_provider: '/your-local/jwt-provider'
});

Generic settings

These settings can be passed to any of the the standalone API methods.

token_provider

This setting could take one of the following two forms:

  • A URL to a page that takes an HTTP JSON POST request and produces a JSON structure with a valid JWT. It uses a POST request to avoid caching by browsers and proxies.
  • A function that provides the same token through a callback. This allows making an HTTP request in any desired format. The provider function is a function that has a success and failure callback where the success takes an object with a token property containing the JWT, and the failure callback takes a string to present as an error message if the token could not be produced.

For more information on how to create these tokens, refer to the JWT authentication guide or try one of the starter projects.

Type: String or Function

Required: yes

Example Using a JWT Provider URL

tinydrive.pick({
  token_provider: '/jwt' // this can be a page or endpoint like this
});

Example Using a JWT Provider Callback

tinydrive.pick({
  token_provider: function (success, failure) {
     success({ token: 'jwt-token' });
     // failure('Could not create a jwt token')
  }
}).then((result) => {
  console.log(result.files);
});

Picker settings

These settings are available for the tinydrive.pick / tinydrive.browse / tinydrive.start methods.

dropbox_app_key

This setting enables specifying the Dropbox API key for integrating dropbox into Tiny Drive. For more information on how you obtain this key, refer to the Dropbox integration guide.

Type: string

Example

tinydrive.pick({
  dropbox_app_key: '<your dropbox app key>',
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});

filetypes

This setting enables restricting what types of files you want do display based on file type categories. For example if your app needs to insert images only then you can specify ['image'] in the file types array.

Type: Array<string>

Example

tinydrive.pick({
  filetypes: ['image'],
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});

google_drive_client_id

This setting enables specifying the Google Drive client ID for integrating Google Drive into Tiny Drive. For more information on how you obtain this ID, refer to the Google Drive integration guide.

Type: string

Example

tinydrive.pick({
  google_drive_client_id: '<your google drive client id>',
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});

google_drive_key

This setting enables specifying the Google Drive API key for integrating Google Drive into Tiny Drive. For more information on how you obtain this key, refer to the Google Drive integration guide.

Type: string

Example

tinydrive.pick({
  google_drive_key: '<your google drive api key>',
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});

max_image_dimension

This setting enables constraining the width/height of uploaded images. When this is enabled any images with a higher width or height than the specified amount would be proportionally resized down to the specified maximum dimension.

Type: Number

Example

tinydrive.pick({
  max_image_dimension: 1024,
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});

target

This setting enables you to render Tiny Drive within a target element by using a CSS selector. If the container has display: flex then the container will be filled with the Tiny Drive UI this could be useful if you want to position the Tiny Drive UI inside your web applications interface.

Type: String

Example

<script>
tinydrive.pick({
  target: '.my-custom-div',
  token_provider: '/your-local/jwt-provider'
}).then((result) => {
  console.log(result.files);
});
</script>
<div class="my-custom-div" style="display: flex; width: 800px; height: 600px">
</div>

Standalone API interfaces

Here is a complete API reference as TypeScript types for developers used to TypeScript syntax.

interface StandaloneApi 
  pick: (settings: StandalonePickerApiSettings) => Promise<PickerResult>;
  browse: (settings: StandalonePickerApiSettings) => Promise<void>;
  start: (settings: StandalonePickerApiSettings) => Promise<void>;
  upload: (settings: StandaloneUploadApiSettings) => Promise<UploadResult>;
}

type TokenProviderCallback = (
  success: (result: TokenResult) => void,
  failure: (error: string) => void
) => void;

interface CommonStandaloneApiSettings {
  token_provider: string | TokenProviderCallback;
}

interface StandalonePickerApiSettings extends CommonStandaloneApiSettings {
  filetypes?: string[];
  dropbox_app_key?: string;
  google_drive_client_id?: string;
  google_drive_key?: string;
  max_image_dimension?: number;
  target?: string;
}

interface StandaloneUploadApiSettings extends CommonStandaloneApiSettings {
  path?: string;
  name: string;
  blob: Blob;
  onprogress?: (details: UploadProgress) => void;
  max_image_dimension?: number;
}

interface DriveFile {
  url: string;
  size: number;
  name: string;
  type: string;
  mdate: string;
}

interface PickerResult {
  files: DriveFile[];
}

interface UploadProgress {
  loaded: number;
  total: number;
}

interface UploadResult {
  file: DriveFile;
}

Can't find what you're looking for? Let us know.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.