README
¶
wasmCloud Blobstore Actor Interface
This package provides wasmCloud actors with an interface to the blobstore capability provider.
Actors using this interface must have the claim wasmcloud:blobstore
in order to have
permission to communicate with the store.
This generic protocol can be used to support capability providers like local blob storage, Amazon S3, Azure blob storage, Google blob storage, and more.
Sample Actor
package main
import (
"strings"
core "github.com/wasmcloud/actor-interfaces/actor-core/go"
httpserver "github.com/wasmcloud/actor-interfaces/http-server/go"
blob "github.com/wasmcloud/actor-interfaces/blobstore/go"
)
func main() {
core.Handlers{HealthRequest: healthRequest}.Register()
httpserver.Handlers{HandleRequest: handleRequest}.Register()
blob.Handlers{ReceiveChunk: receiveChunk}.Register()
}
func receiveChunk(chunk blob.FileChunk) error {
// ReceiveChunk is used to process incoming file chunks, as downloading an entire file
// may exceed the memory capacity of the WebAssembly module.
//
// This is effectively streaming a file download to the module, so you must use
// the chunk `Context`, `TotalBytes` and `ChunkBytes` fields to determine
// when you have received all of the bytes for a file.
return nil
}
func handleRequest(request httpserver.Request) (httpserver.Response, error) {
switch method := request.Method; method {
case "GET":
return downloadImage()
case "POST":
return uploadImage(request.Path, request.Body)
default:
return httpserver.Response{
StatusCode: 400,
Status: "Bad Request",
Body: nil,
}, nil
}
}
func downloadImage() (httpserver.Response, error) {
blobStore := blob.NewHost("default")
blobStore.StartDownload("myblob", "folder", 512, nil)
return httpserver.Response{
StatusCode: 200,
Status: "OK",
Body: []byte("Download started"),
}, nil
}
func uploadImage(path string, imageBytes []byte) (httpserver.Response, error) {
blobStore := blob.NewHost("default")
container := blob.Container {
ID: "folder",
}
image := blob.FileChunk {
SequenceNo: 0,
Container: container,
ID: strings.ReplaceAll(path, "/", ""),
TotalBytes: uint64(len(imageBytes)),
ChunkSize: uint64(len(imageBytes)),
Context: nil,
ChunkBytes: imageBytes,
}
blobStore.StartUpload(image)
blobStore.UploadChunk(image)
return httpserver.Response{
StatusCode: 200,
Status: "OK",
Body: []byte("Uploaded Successfully"),
}, nil
}
func healthRequest(request core.HealthCheckRequest) (core.HealthCheckResponse, error) {
return core.HealthCheckResponse{
Healthy: true,
}, nil
}
Documentation
¶
Index ¶
- type Blob
- type BlobList
- type BlobstoreResult
- type Container
- type ContainerList
- type CreateContainerArgs
- type FileChunk
- type GetObjectInfoArgs
- type Handlers
- type Host
- func (h *Host) CreateContainer(id string) (Container, error)
- func (h *Host) GetObjectInfo(blobID string, containerID string) (Blob, error)
- func (h *Host) ListObjects(containerID string) (BlobList, error)
- func (h *Host) RemoveContainer(id string) (BlobstoreResult, error)
- func (h *Host) RemoveObject(id string, containerID string) (BlobstoreResult, error)
- func (h *Host) StartDownload(blobID string, containerID string, chunkSize uint64, context *string) (BlobstoreResult, error)
- func (h *Host) StartUpload(chunk FileChunk) (BlobstoreResult, error)
- func (h *Host) UploadChunk(chunk FileChunk) (BlobstoreResult, error)
- type ListObjectsArgs
- type ReceiveChunkArgs
- type RemoveContainerArgs
- type RemoveObjectArgs
- type StartDownloadArgs
- type StartUploadArgs
- type Transfer
- type UploadChunkArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Blob ¶
A blob is a representation of an object in a blobstore, similar to a file in a file system.
type BlobList ¶
type BlobList struct {
Blobs []Blob
}
A wrapper object around a list of blobs.
func DecodeBlobListNullable ¶
type BlobstoreResult ¶
Used to return success and error information for common blobstore operations
func DecodeBlobstoreResult ¶
func DecodeBlobstoreResult(decoder *msgpack.Decoder) (BlobstoreResult, error)
func DecodeBlobstoreResultNullable ¶
func DecodeBlobstoreResultNullable(decoder *msgpack.Decoder) (*BlobstoreResult, error)
type Container ¶
type Container struct {
ID string
}
A container is a logical grouping of blobs, similar to a directory in a file system.
func DecodeContainerNullable ¶
type ContainerList ¶
type ContainerList struct {
Containers []Container
}
A wrapper object around a list of containers.
func DecodeContainerList ¶
func DecodeContainerList(decoder *msgpack.Decoder) (ContainerList, error)
func DecodeContainerListNullable ¶
func DecodeContainerListNullable(decoder *msgpack.Decoder) (*ContainerList, error)
type CreateContainerArgs ¶
type CreateContainerArgs struct {
ID string
}
func DecodeCreateContainerArgs ¶
func DecodeCreateContainerArgs(decoder *msgpack.Decoder) (CreateContainerArgs, error)
func DecodeCreateContainerArgsNullable ¶
func DecodeCreateContainerArgsNullable(decoder *msgpack.Decoder) (*CreateContainerArgs, error)
type FileChunk ¶
type FileChunk struct { SequenceNo uint64 Container Container ID string TotalBytes uint64 ChunkSize uint64 Context *string ChunkBytes []byte }
Represents a single chunk that may comprise part of a file or an entire file. The fields for sequence number, total bytes and chunk bytes should be used to determine the chunk order, as well as the optional context field.
func DecodeFileChunkNullable ¶
type GetObjectInfoArgs ¶
func DecodeGetObjectInfoArgs ¶
func DecodeGetObjectInfoArgs(decoder *msgpack.Decoder) (GetObjectInfoArgs, error)
func DecodeGetObjectInfoArgsNullable ¶
func DecodeGetObjectInfoArgsNullable(decoder *msgpack.Decoder) (*GetObjectInfoArgs, error)
type Handlers ¶
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
func (*Host) CreateContainer ¶
Create a container in a blobstore. Returns the container created if successful
func (*Host) GetObjectInfo ¶
Retreives information about a blob
func (*Host) ListObjects ¶
Returns a list of blobs that are present in the specified container
func (*Host) RemoveContainer ¶
func (h *Host) RemoveContainer(id string) (BlobstoreResult, error)
Remove a container from a blobstore
func (*Host) RemoveObject ¶
func (h *Host) RemoveObject(id string, containerID string) (BlobstoreResult, error)
Remove an object from a blobstore
func (*Host) StartDownload ¶
func (h *Host) StartDownload(blobID string, containerID string, chunkSize uint64, context *string) (BlobstoreResult, error)
Issue a request to start a download from a blobstore. Chunks will be sent to the function that's registered with the ReceiveChunk operation.
func (*Host) StartUpload ¶
func (h *Host) StartUpload(chunk FileChunk) (BlobstoreResult, error)
Begin the upload process with the first chunk of a full file. Subsequent chunks should be uploaded with the UploadChunk operation.
func (*Host) UploadChunk ¶
func (h *Host) UploadChunk(chunk FileChunk) (BlobstoreResult, error)
Upload a file chunk to a blobstore, which may only be part of a full file. This must be called AFTER the StartUpload operation. Chunks should be small, as memory over a few megabytes may exceed the wasm memory allocation.
type ListObjectsArgs ¶
type ListObjectsArgs struct {
ContainerID string
}
func DecodeListObjectsArgs ¶
func DecodeListObjectsArgs(decoder *msgpack.Decoder) (ListObjectsArgs, error)
func DecodeListObjectsArgsNullable ¶
func DecodeListObjectsArgsNullable(decoder *msgpack.Decoder) (*ListObjectsArgs, error)
type ReceiveChunkArgs ¶
type ReceiveChunkArgs struct {
Chunk FileChunk
}
func DecodeReceiveChunkArgs ¶
func DecodeReceiveChunkArgs(decoder *msgpack.Decoder) (ReceiveChunkArgs, error)
func DecodeReceiveChunkArgsNullable ¶
func DecodeReceiveChunkArgsNullable(decoder *msgpack.Decoder) (*ReceiveChunkArgs, error)
type RemoveContainerArgs ¶
type RemoveContainerArgs struct {
ID string
}
func DecodeRemoveContainerArgs ¶
func DecodeRemoveContainerArgs(decoder *msgpack.Decoder) (RemoveContainerArgs, error)
func DecodeRemoveContainerArgsNullable ¶
func DecodeRemoveContainerArgsNullable(decoder *msgpack.Decoder) (*RemoveContainerArgs, error)
type RemoveObjectArgs ¶
func DecodeRemoveObjectArgs ¶
func DecodeRemoveObjectArgs(decoder *msgpack.Decoder) (RemoveObjectArgs, error)
func DecodeRemoveObjectArgsNullable ¶
func DecodeRemoveObjectArgsNullable(decoder *msgpack.Decoder) (*RemoveObjectArgs, error)
type StartDownloadArgs ¶
func DecodeStartDownloadArgs ¶
func DecodeStartDownloadArgs(decoder *msgpack.Decoder) (StartDownloadArgs, error)
func DecodeStartDownloadArgsNullable ¶
func DecodeStartDownloadArgsNullable(decoder *msgpack.Decoder) (*StartDownloadArgs, error)
type StartUploadArgs ¶
type StartUploadArgs struct {
Chunk FileChunk
}
func DecodeStartUploadArgs ¶
func DecodeStartUploadArgs(decoder *msgpack.Decoder) (StartUploadArgs, error)
func DecodeStartUploadArgsNullable ¶
func DecodeStartUploadArgsNullable(decoder *msgpack.Decoder) (*StartUploadArgs, error)
type Transfer ¶
type Transfer struct { BlobID string Container Container ChunkSize uint64 TotalSize uint64 TotalChunks uint64 Context *string }
func DecodeTransferNullable ¶
type UploadChunkArgs ¶
type UploadChunkArgs struct {
Chunk FileChunk
}
func DecodeUploadChunkArgs ¶
func DecodeUploadChunkArgs(decoder *msgpack.Decoder) (UploadChunkArgs, error)
func DecodeUploadChunkArgsNullable ¶
func DecodeUploadChunkArgsNullable(decoder *msgpack.Decoder) (*UploadChunkArgs, error)