Storage
The storage package selects the provider from CLOUD: aws uses Amazon S3,
while gcp and firebase use Google Cloud Storage.
Initialize
Configure credentials through the provider's standard mechanism, then:
colibri.InitializeApp()
storage.Initialize()
CLOUD=none does not create a storage provider.
Upload a form file
In v0.2.2, UploadFile receives *multipart.File:
file, header, err := ctx.FormFile("file")
if err != nil {
ctx.ErrorResponse(http.StatusBadRequest, err)
return
}
defer file.Close()
location, err := storage.UploadFile(
ctx.Context(),
"documents",
header.Filename,
&file,
)
Download and remove
file, err := storage.DownloadFile(ctx, "documents", objectKey)
if err != nil {
return err
}
defer file.Close()
content, err := io.ReadAll(file)
The returned value is a temporary *os.File; always close it.
err := storage.DeleteFile(ctx, "documents", objectKey)
The v0.2.2 upload API does not accept a generic reader. The bucket must already exist, and the application identity needs permission for each operation.