UploadThing

Use UploadThing UFS as a Files SDK backend with custom IDs as keys.

Create the adapter

package main

import (
	"context"
	"os"

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

func newClient(ctx context.Context) (*files.Client, error) {
	adapter, err := uploadthing.New(uploadthing.Options{
		Token: os.Getenv("UPLOADTHING_TOKEN"),
		ACL: uploadthing.ACLPublicRead,
	})
	if err != nil {
		return nil, err
	}

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

Environment variables

When Token is empty, the adapter reads:

VariablePurpose
UPLOADTHING_TOKENUploadThing token.

Signed upload URLs

UploadThing signed upload URLs include the provider-specific headers and fields needed by clients.

upload, err := client.SignedUploadURL(ctx, "uploads/report.pdf", files.SignedUploadOptions{
	ContentType: "application/pdf",
	ExpiresIn: 10 * time.Minute,
})
if err != nil {
	return err
}

fmt.Println(upload.Method, upload.URL)

UploadThing uses custom IDs as Files SDK keys.

On this page