Code Monkey home page Code Monkey logo

active-storage's Introduction

Current Crates.io Version

Active Storage

Active Storage streamlines the process of uploading files to cloud storage, offering both local disk-based and in-memory services for development and testing. Additionally, it supports mirroring files to subordinate services, enhancing capabilities for backups and migrations.

It's inspired by Rails Active Store

Services

Single Store Usage Example

use std::path::PathBuf;
use active_storage::{drivers, StoreConfig};

#[tokio::main]
async fn main() {
    let config = drivers::aws_s3::Config {
        region: "us-east-1".to_string(),
        bucket: "test-bucket".to_string(),
        credentials: None,
    };
    let s3_driver = StoreConfig::AwsS3(config).build().await.unwrap();

    let file_path = PathBuf::from("test.txt");
    s3_driver
        .write(file_path.as_path(), b"my content")
        .await
        .unwrap();
}

Mirroring Usage Example

use std::{collections::HashMap, path::PathBuf};
use active_storage::{drivers, multi_store::MultiStore, StoreConfig};

#[tokio::main]
async fn main() {
    let config = drivers::disk::Config {
        location: PathBuf::from("tmp").join("primary-storage"),
    };
    let store_one = StoreConfig::Disk(config).build().await.unwrap();

    let config = drivers::disk::Config {
        location: PathBuf::from("tmp").join("backups"),
    };
    let secondary_store = StoreConfig::Disk(config).build().await.unwrap();

    let mut multi_store = MultiStore::new(store_one);
    multi_store.add_stores(HashMap::from([("secondary", secondary_store)]));

    let _ = multi_store
        .mirror_stores_from_primary()
        .write(PathBuf::from("test").as_path(), b"content")
        .await;
}

active-storage's People

Contributors

kaplanelad avatar

Stargazers

Walla Lewis  avatar Jorge Valdez avatar  avatar fan-tastic-z avatar

Watchers

 avatar  avatar

active-storage's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.