Appwrite

Use Appwrite Storage as a Files SDK backend through the Storage REST API.

Create the adapter

package main

import (
	"context"

	files "github.com/cersho/gofiles-sdk"
	"github.com/cersho/gofiles-sdk/providers/appwrite"
)

func newClient(ctx context.Context) (*files.Client, error) {
	adapter, err := appwrite.New(appwrite.Options{
		Bucket: "uploads",
	})
	if err != nil {
		return nil, err
	}

	return files.New(files.Options{Adapter: adapter})
}

Environment variables

When options are empty, the adapter reads:

VariablePurpose
APPWRITE_ENDPOINTAppwrite API endpoint. Defaults to https://cloud.appwrite.io/v1.
NEXT_PUBLIC_APPWRITE_ENDPOINTEndpoint fallback.
APPWRITE_PROJECT_IDAppwrite project ID.
NEXT_PUBLIC_APPWRITE_PROJECT_IDProject ID fallback.
APPWRITE_API_KEYAppwrite API key.
APPWRITE_KEYAPI key fallback.

Public URLs

URL returns a permanent Appwrite view URL only when the bucket is public and the adapter is created with Public: true.

adapter, err := appwrite.New(appwrite.Options{
	Bucket: "uploads",
	Public: true,
})

Resumable uploads

Appwrite resumable uploads use Appwrite's chunked file upload endpoint through files.UploadControl. Chunks are fixed at 5 MiB, matching Appwrite's API.

control := files.NewUploadControl()

_, err := client.Upload(ctx, "video_intro", files.FileBody("intro.mp4"), files.UploadOptions{
	ContentType: "video/mp4",
	Control:     control,
})

Limitations

Appwrite file IDs are used as Files SDK keys. They must start with an alphanumeric character, use only letters, digits, ., _, and -, and be at most 36 characters. Slashes are not supported.

List prefix filtering queries Appwrite's name field because Appwrite Storage does not expose $id as a documented list filter field. Files uploaded through this adapter use the key as both file ID and uploaded filename, so prefix list works for adapter-created files.

metadata, cacheControl, signed upload URLs, signed read URLs, and server-side copy are not supported by Appwrite Storage. Copy downloads the source and uploads the destination.

Compatibility

MethodStatusNotes
uploadPartialAppwrite chooses the stored MIME type. Metadata and cache-control are not supported.
downloadYes
deleteYes
listYesPrefix filters use Appwrite queries against name; directory-style delimiter listing is not supported.
searchYesUses SDK list/search behavior.
headYesExposes a lazy body.
existsYesReturns false only for provider NotFound responses.
copyPartialRead-then-write; not server-side or atomic.
urlPartialPublic bucket permanent view URL only.
signedUploadUrlNoAppwrite has no presigned upload primitive.

On this page