Storage

SERVER

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.

Files are managed using buckets. Storage buckets are similar to Collections we have in our Databases service. The difference is, buckets also provide more power to decide what kinds of files, what sizes you want to allow in that bucket, whether or not to encrypt the files, scan with antivirus and more.

Using Appwrite permissions architecture, you can assign read or write access to each bucket or file in your project for either a specific user, team, user role, or even grant it with public access (any). You can learn more about how Appwrite handles permissions and access control.

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.

Base URL
https://cloud.appwrite.io/v1

List buckets

Get a list of all the storage buckets. You can use the query params to filter your results.

  • Request
    • search string

      Search term to filter your list results. Max length: 256 chars.

    • limit integer

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

    • offset integer

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

    • cursor string

      ID of the bucket used as the starting point for the query, excluding the bucket itself. Should be used for efficient pagination when working with large sets of data.

    • cursorDirection string

      Direction of the cursor, can be either 'before' or 'after'.

    • orderType string

      Order result by ASC or DESC order.

  • Response
Endpoint
GET /storage/buckets
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.listBuckets(
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Create bucket

Create a new storage bucket.

  • Request
    • bucketId string
      required

      Unique Id. Choose your own unique ID or pass the string unique() to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • name string
      required

      Bucket name

    • permission string
      required

      Permissions type model to use for reading files in this bucket. You can use bucket-level permission set once on the bucket using the read and write params, or you can set file-level permission where each file read and write params will decide who has access to read and write to each file individually. learn more about permissions and get a full list of available permissions.

    • read 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 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.

    • enabled boolean

      Is bucket enabled?

    • maximumFileSize integer

      Maximum file size allowed in bytes. Maximum allowed value is 30MB. For self-hosted setups you can change the max limit by changing the _APP_STORAGE_LIMIT environment variable. Learn more about storage environment variables

    • allowedFileExtensions array

      Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.

    • encryption boolean

      Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled

    • antivirus boolean

      Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled

  • Response
Endpoint
POST /storage/buckets
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.createBucket(
        bucketId = "[BUCKET_ID]",
        name = "[NAME]",
        permission = "file",
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Get Bucket

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

  • Request
    • bucketId string
      required

      Bucket unique ID.

  • Response
Endpoint
GET /storage/buckets/{bucketId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.getBucket(
        bucketId = "[BUCKET_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Update Bucket

Update a storage bucket by its unique ID.

  • Request
    • bucketId string
      required

      Bucket unique ID.

    • name string
      required

      Bucket name

    • permission string
      required

      Permissions type model to use for reading files in this bucket. You can use bucket-level permission set once on the bucket using the read and write params, or you can set file-level permission where each file read and write params will decide who has access to read and write to each file individually. learn more about permissions and get a full list of available permissions.

    • read array

      An array of strings with read permissions. By default inherits the existing read permissions. learn more about permissions and get a full list of available permissions.

    • write array

      An array of strings with write permissions. By default inherits the existing write permissions. learn more about permissions and get a full list of available permissions.

    • enabled boolean

      Is bucket enabled?

    • maximumFileSize integer

      Maximum file size allowed in bytes. Maximum allowed value is 30MB. For self hosted version you can change the limit by changing _APP_STORAGE_LIMIT environment variable. Learn more about storage environment variables

    • allowedFileExtensions array

      Allowed file extensions. Maximum of 100 extensions are allowed, each 64 characters long.

    • encryption boolean

      Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled

    • antivirus boolean

      Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled

  • Response
Endpoint
PUT /storage/buckets/{bucketId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.updateBucket(
        bucketId = "[BUCKET_ID]",
        name = "[NAME]",
        permission = "file",
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Delete Bucket

Delete a storage bucket by its unique ID.

  • Request
    • bucketId string
      required

      Bucket unique ID.

  • Response
    • 204 application/json
Endpoint
DELETE /storage/buckets/{bucketId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.deleteBucket(
        bucketId = "[BUCKET_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

List 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's files. Learn more about different API modes.

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • search string

      Search term to filter your list results. Max length: 256 chars.

    • limit integer

      Maximum number of files to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

    • cursor string

      ID of the file used as the starting point for the query, excluding the file itself. Should be used for efficient pagination when working with large sets of data. learn more about pagination

    • cursorDirection string

      Direction of the cursor, can be either 'before' or 'after'.

    • orderType string

      Order result by ASC or DESC order.

  • Response
Endpoint
GET /storage/buckets/{bucketId}/files
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.listFiles(
        bucketId = "[BUCKET_ID]",
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Create File

Create a new file. Before using this route, you should create a new bucket resource using either a server integration API or directly from your Appwrite console.

Larger files should be uploaded using multiple requests with the content-range header to send a partial request with a maximum supported chunk of 5MB. The content-range header values should always be in bytes.

When the first request is sent, the server will return the File object, and the subsequent part request must include the file's id in x-appwrite-id header to allow the server to know that the partial upload is for the existing file and not for a new one.

If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally.

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • file string
      required

      Binary file.

    • read array

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

    • write array

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

  • Response
    • 201 application/json
Endpoint
POST /storage/buckets/{bucketId}/files
Java
import io.appwrite.Client
import io.appwrite.models.InputFile
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.createFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]",
        file = InputFile.fromPath("file.png"),
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Get File

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

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID.

  • Response
    • 200 application/json
Endpoint
GET /storage/buckets/{bucketId}/files/{fileId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.getFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Update File

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

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File unique ID.

    • read 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 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.

  • Response
    • 200 application/json
Endpoint
PUT /storage/buckets/{bucketId}/files/{fileId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.updateFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]",
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Delete File

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

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID.

  • Response
    • 204 application/json
Endpoint
DELETE /storage/buckets/{bucketId}/files/{fileId}
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.deleteFile(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Get File for Download

Get a 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.

  • Request
    • bucketId string
      required

      Storage bucket ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID.

  • Response
    • 200 application/json
Endpoint
GET /storage/buckets/{bucketId}/files/{fileId}/download
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.getFileDownload(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Get File 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. Preview is supported only for image files smaller than 10MB.

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID

    • width integer

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

    • height integer

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

    • gravity string

      Image crop gravity. Can be one of center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right

    • quality integer

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

    • borderWidth integer

      Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.

    • borderColor string

      Preview image border color. Use a valid HEX color, no # is needed for prefix.

    • borderRadius integer

      Preview image border radius in pixels. Pass an integer between 0 to 4000.

    • opacity number

      Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.

    • rotation integer

      Preview image rotation in degrees. Pass an integer between -360 and 360.

    • background string

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

    • output string

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

  • Response
    • 200 application/json
Endpoint
GET /storage/buckets/{bucketId}/files/{fileId}/preview
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.getFilePreview(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]",
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}

Get File for View

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

  • Request
    • bucketId string
      required

      Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

    • fileId string
      required

      File ID.

  • Response
    • 200 application/json
Endpoint
GET /storage/buckets/{bucketId}/files/{fileId}/view
Java
import io.appwrite.Client
import io.appwrite.services.Storage

public void main() {
    Client client = Client(context)
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setKey("919c2d18fb5d4...a2ae413da83346ad2"); // Your secret API key

    Storage storage = new Storage(client);
    storage.getFileView(
        bucketId = "[BUCKET_ID]",
        fileId = "[FILE_ID]"
        new Continuation<Response>() {
            @NotNull
            @Override
            public CoroutineContext getContext() {
                return EmptyCoroutineContext.INSTANCE;
            }

            @Override
            public void resumeWith(@NotNull Object o) {
                String json = "";
                try {
                    if (o instanceof Result.Failure) {
                        Result.Failure failure = (Result.Failure) o;
                        throw failure.exception;
                    } else {
                        Response response = (Response) o;
                    }
                } catch (Throwable th) {
                    Log.e("ERROR", th.toString());
                }
            }
        }
    );
}