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 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 it will fit perfectly inside your app.

List Files

GET/storage/files

Get a list of all the user files. You can use the query params to filter your results. On managed 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('')
        setKey('')
    ;
    
    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();

Get File

GET/storage/files/{id}

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

Arguments

Name Type Description
id required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        setProject('')
        setKey('')
    ;
    
    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]');

Preview File

GET/storage/files/{id}/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
id 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('')
        setKey('')
    ;
    
    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]');

Download File

GET/storage/files/{id}/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
id required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        setProject('')
        setKey('')
    ;
    
    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]');

View File

GET/storage/files/{id}/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
id 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('')
        setKey('')
    ;
    
    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]');

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 optional array

An array of read permissions. Learn more about permissions and roles.

write optional array

An array of write permissions. Learn more about permissions and roles.

folderId optional string

Folder to associate files with.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        setProject('')
        setKey('')
    ;
    
    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'));

Delete File

DELETE/storage/files/{id}

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

Arguments

Name Type Description
id required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        setProject('')
        setKey('')
    ;
    
    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]');