Docs

Storage

The storage service allows you to manage your project files. You can upload, view, download, and query your files and media.

Each file is granted read and write permissions to manage who has access to view or manage it. You can also learn more about how to manage your resources permissions.

You can also use the storage service file preview endpoint to show the app users' preview images of your files. The preview endpoint also allows you to manipulate the resulting image so that it will fit perfectly inside your app in terms of size and style.

List Files

GET/storage/files

Get a list of all the user files. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project files. Learn more about different API modes.

Arguments

Name Type Description
search optional string

Search term to filter your list results.

limit optional integer

Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.

offset optional integer

Results offset. The default value is 0. Use this param to manage pagination.

orderType optional string

Order result by ASC or DESC order.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.listFiles();
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->listFiles();
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.listFiles();
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Get File

GET/storage/files/{fileId}

Get file by its unique ID. This endpoint response returns a JSON object with the file metadata.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.getFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFile('[FILE_ID]');
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.getFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Get File Preview

GET/storage/files/{fileId}/preview

Get file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets will return file icon image. You can also pass query string arguments for cutting and resizing your preview image.

Arguments

Name Type Description
fileId required string

File unique ID

width optional integer

Resize preview image width, Pass an integer between 0 to 4000

height optional integer

Resize preview image height, Pass an integer between 0 to 4000

quality optional integer

Preview image quality. Pass an integer between 0 to 100. Defaults to 100

background optional string

Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.

output optional string

Output format type (jpeg, jpg, png, gif and webp)

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.getFilePreview('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFilePreview('[FILE_ID]');
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.getFilePreview('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Get File for Download

GET/storage/files/{fileId}/download

Get file content by its unique ID. The endpoint response return with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to user downloads directory.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.getFileDownload('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFileDownload('[FILE_ID]');
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.getFileDownload('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Get File for View

GET/storage/files/{fileId}/view

Get file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.

Arguments

Name Type Description
fileId required string

File unique ID.

as optional string

Choose a file format to convert your file to. Currently you can only convert word and pdf files to pdf or txt. This option is currently experimental only, use at your own risk.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.getFileView('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFileView('[FILE_ID]');
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.getFileView('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Create File

POST/storage/files

Create a new file. The user who creates the file will automatically be assigned to read and write access unless he has passed custom values for read and write arguments.

Arguments

Name Type Description
files required file

Binary Files.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. learn more about permissions and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

folderId optional string

Folder to associate files with.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.createFile(document.getElementById('uploader').files[0], [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->createFile(new \CURLFile('/path/to/file.png', 'image/png', 'file.png'), [], []);
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.createFile(document.getElementById('uploader').files[0], [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Update File

PUT/storage/files/{fileId}

Update file by its unique ID. Only users with write permissions have access to update this resource.

Arguments

Name Type Description
fileId required string

File unique ID.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. learn more about permissions and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

folderId optional string

Folder to associate files with.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.updateFile('[FILE_ID]', [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->updateFile('[FILE_ID]', [], []);
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.updateFile('[FILE_ID]', [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });

Delete File

DELETE/storage/files/{fileId}

Delete a file by its unique ID. Only users with write permissions have access to delete this resource.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('')
    ;
    
    let promise = sdk.storage.deleteFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Storage;
    
    $client = new Client();
    
    $client
        ->setProject('')
        ->setKey('')
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->deleteFile('[FILE_ID]');
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('')
        .setKey('')
    ;
    
    let promise = storage.deleteFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });