Crate wasmcloud_actor_blobstore[−][src]
wasmCloud Blob Store Actor Interface
This crate 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.
//! Example:
extern crate wapc_guest as guest; use guest::prelude::*; use wasmcloud_actor_blobstore as blobstore; use wasmcloud_actor_http_server as http; use wasmcloud_actor_core::serialize; use wasmcloud_actor_core as actor_core; use blobstore::*; use serde_json::json; use log::{error, info}; #[no_mangle] pub fn wapc_init() { http::Handlers::register_handle_request(download_poem); blobstore::Handlers::register_receive_chunk(handle_chunk); actor_core::Handlers::register_health_request(health); } /// Start the download of a blob (poem). Chunks will be streamed after download begins fn download_poem(req: http::Request) -> HandlerResult<http::Response> { let stream_request = StreamRequest { id: req.path, container: Container::new("photos".to_string()), chunk_size: 4096, context: None }; // replace `start_download` with `blobstore::default().start_download` match start_download(stream_request) { Ok(_) => Ok(http::Response::ok()), Err(_) => Err("Failed to initiate download of chunk".into()) } } /// Handle the incoming chunk as a poem "verse" and log the result /// Note that these chunks can be received out of order, so the poem /// in this case might be displayed in a different order. fn handle_chunk(chunk: FileChunk) -> HandlerResult<()> { let verse = String::from_utf8(chunk.chunk_bytes)?; info!("Poem {} part {}:\n{}", chunk.id, chunk.sequence_no, verse); Ok(()) } fn health(_: actor_core::HealthCheckRequest) -> HandlerResult<actor_core::HealthCheckResponse> { Ok(actor_core::HealthCheckResponse::healthy()) }
Structs
Constants
OP_CREATE_CONTAINER | Guest sends a Container to the capability provider, receives a Container back |
OP_GET_OBJECT_INFO | Query information on a single blob. Guest sends an incomplete blob struct and gets a complete one in return |
OP_LIST_OBJECTS | Guest sends a Container to the capability provider, receives a BlobList back |
OP_RECEIVE_CHUNK | Guest will receive a FileChunk for each piece of a file requested to download |
OP_REMOVE_CONTAINER | Guest sends a Container to the capability provider, lack of error indicates success |
OP_REMOVE_OBJECT | Guest sends a Blob to the capability provider, lack of error indicates success |
OP_START_DOWNLOAD | Guest sends a StreamRequest to the capability provider, immediate termination w/success. Guest will then start receiving OP_RECEIVE_CHUNK operations from the provider as chunks are streamed to the guest |
OP_START_UPLOAD | Guest sends a metadata-carrying FileChunk to initiate an upload, lack of error is success |
OP_UPLOAD_CHUNK | Guest sends a FileChunk to capability provider for storing as part of a Blob, lack of error indicates success |
Functions
deserialize | The standard function for de-serializing codec structs from a format suitable for message exchange between actor and host. Use of any other function to deserialize could result in breaking incompatibilities. |
serialize | The standard function for serializing codec structs into a format that can be used for message exchange between actor and host. Use of any other function to serialize could result in breaking incompatibilities. |