Version 0.5.3  
Docs

Storage API

Showing API references for integration, using code examples.


The Storage service allows you to manage your project files. Using the Storage service, you can upload, view, download, and query all your project files.

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

The preview endpoint allows you to generate preview images for your files. Using the preview endpoint, you can also manipulate the resulting image so that it will fit perfectly inside your app in terms of dimensions, file size, and style. The preview endpoint also allows you to change the resulting image file format for better compression or image quality for better delivery over the network.

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.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.write" permission scope.

Arguments

Name Type Description
file required file

Binary File.

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.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('5df5acd0d48c2') // Your project ID
    ;
    
    let promise = sdk.storage.createFile(document.getElementById('uploader').files[0], [], []);
    
    promise.then(function (response) {
        console.log(response); // Success
    }, function (error) {
        console.log(error); // Failure
    });
  • const sdk = require('node-appwrite');
    const fs = require('fs');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = storage.createFile(fs.createReadStream(__dirname + '/file.png')), [], []);
    
    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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->createFile(new \CURLFile('/path/to/file.png', 'image/png', 'file.png'), [], []);
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.create_file(document.getElementById('uploader').files[0], {}, {})
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.CreateFile(file, [], [])
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

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.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.read" permission scope.

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('5df5acd0d48c2') // Your project ID
    ;
    
    let promise = sdk.storage.listFiles();
    
    promise.then(function (response) {
        console.log(response); // Success
    }, function (error) {
        console.log(error); // Failure
    });
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->listFiles();
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.list_files()
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.ListFiles("[SEARCH]", 0, 0, "ASC")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

Get File

GET/storage/files/{fileId}

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

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.read" permission scope.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('5df5acd0d48c2') // Your project ID
    ;
    
    let promise = sdk.storage.getFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response); // Success
    }, function (error) {
        console.log(error); // Failure
    });
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFile('[FILE_ID]');
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.get_file('[FILE_ID]')
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.GetFile("[FILE_ID]")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

Get File Preview

GET/storage/files/{fileId}/preview

Get a 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 the file icon image. You can also pass query string arguments for cutting and resizing your preview image.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.read" permission scope.

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('5df5acd0d48c2') // Your project ID
    ;
    
    let result = sdk.storage.getFilePreview('[FILE_ID]');
    
    console.log(result); // Resource URL
    
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFilePreview('[FILE_ID]');
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.get_file_preview('[FILE_ID]')
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.GetFilePreview("[FILE_ID]", 0, 0, 0, "", "jpg")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

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.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.read" permission scope.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('5df5acd0d48c2') // Your project ID
    ;
    
    let result = sdk.storage.getFileDownload('[FILE_ID]');
    
    console.log(result); // Resource URL
    
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFileDownload('[FILE_ID]');
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.get_file_download('[FILE_ID]')
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.GetFileDownload("[FILE_ID]")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

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.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.read" permission scope.

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('5df5acd0d48c2') // Your project ID
    ;
    
    let result = sdk.storage.getFileView('[FILE_ID]');
    
    console.log(result); // Resource URL
    
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->getFileView('[FILE_ID]');
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.get_file_view('[FILE_ID]')
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.GetFileView("[FILE_ID]", "pdf")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

Update File

PUT/storage/files/{fileId}

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

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.write" permission scope.

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.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('5df5acd0d48c2') // Your project ID
    ;
    
    let promise = sdk.storage.updateFile('[FILE_ID]', [], []);
    
    promise.then(function (response) {
        console.log(response); // Success
    }, function (error) {
        console.log(error); // Failure
    });
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->updateFile('[FILE_ID]', [], []);
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.update_file('[FILE_ID]', {}, {})
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.UpdateFile("[FILE_ID]", [], [])
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }

Delete File

DELETE/storage/files/{fileId}

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

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "files.write" permission scope.

Arguments

Name Type Description
fileId required string

File unique ID.

Example Request
  • let sdk = new Appwrite();
    
    sdk
        .setProject('5df5acd0d48c2') // Your project ID
    ;
    
    let promise = sdk.storage.deleteFile('[FILE_ID]');
    
    promise.then(function (response) {
        console.log(response); // Success
    }, function (error) {
        console.log(error); // Failure
    });
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let storage = new sdk.Storage(client);
    
    client
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = 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('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $storage = new Storage($client);
    
    $result = $storage->deleteFile('[FILE_ID]');
  • from appwrite.client import Client
    from appwrite.services.storage import Storage
    
    client = Client()
    
    (client
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    storage = Storage(client)
    
    result = storage.delete_file('[FILE_ID]')
    
  • package main
    
    import (
        "fmt"
        "github.com/appwrite/sdk-for-go"
    )
    
    func main() {
        var client := appwrite.Client{}
    
        client.SetProject("5df5acd0d48c2") // Your project ID
        client.SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    
        var service := appwrite.Storage{
            client: &client
        }
    
        var response, error := service.DeleteFile("[FILE_ID]")
    
        if error != nil {
            panic(error)
        }
    
        fmt.Println(response)
    }