Buckets

Before proceeding

Ensure you install the CLI, log in to your Appwrite account, and initialize your Appwrite project.

The Appwrite CLI allows you to configure and deploy buckets across projects. You can also configure your files using the CLI commands.

Initialize bucket

Create a new bucket using the following command:

Shell
appwrite init buckets

Pull bucket

You can also pull your existing Appwrite buckets from the Appwrite Console using the pull command in the folder containing your appwrite.json file.

Shell
appwrite pull buckets

appwrite.json

After initializing your Appwrite project and pulling your existing buckets, your appwrite.json file should look similar to the following:

JSON
{
    "projectId": "<PROJECT_ID>",
    "buckets": [
        {
            "$id": "<BUCKET_ID>",
            "$createdAt": "2024-06-21T16:20:25.516+00:00",
            "$updatedAt": "2024-06-21T16:21:16.855+00:00",
            "$permissions": [
                "create(\"any\")",
                "read(\"any\")",
                "update(\"any\")",
                "delete(\"any\")"
            ],
            "fileSecurity": false,
            "name": "test",
            "enabled": true,
            "maximumFileSize": 5368709120,
            "allowedFileExtensions": [],
            "compression": "none",
            "encryption": true,
            "antivirus": true
        }
    ]
}

Push bucket

Use the push command in the folder containing your appwrite.json file to push the changes you made.

Shell
appwrite push buckets

Commands

The storage command allows you to manage your project's buckets and files. Appwrite storage CLI commands generally follow the following syntax:

Shell
appwrite storage [COMMAND] [OPTIONS]
CommandDescription
list-buckets [options]Get a list of all the storage buckets. You can use the query params to filter your results.
create-bucket [options]Create a new storage bucket.
get-bucket [options]Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.
update-bucket [options]Update a storage bucket by its unique ID.
delete-bucket [options]Delete a storage bucket by its unique ID.
list-files [options]Get a list of all the user files. You can use the query params to filter your results.
create-file [options]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.
get-file [options]Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.
update-file [options]Update a file by its unique ID. Only users with write permissions have access to update this resource.
delete-file [options]Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
get-file-download [options]Get a file content by its unique ID. The endpoint response returns with a 'Content-Disposition: attachment' header that tells the browser to start downloading the file to the user downloads directory.
get-file-preview [options]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.
get-file-view [options]Get a file content by its unique ID. This endpoint is similar to the download method but returns with no 'Content-Disposition: attachment' header.