Code Monkey home page Code Monkey logo

liquid's Introduction

Liquid

Abstract file storage component made for Vapor 4 using the LiquidKit file storage solution.

Supported drivers

โš ๏ธ In order to use the AWS S3 driver you have to configure your credentials.

Usage example

Add Liquid as a dependency using SPM (with the driver that you'd like to use):

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "myProject",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", from: "4.41.0"),
        .package(url: "https://github.com/binarybirds/liquid.git", from: "1.2.0"),
        .package(url: "https://github.com/binarybirds/liquid-local-driver.git", from: "1.2.0"),
        .package(url: "https://github.com/binarybirds/liquid-aws-s3-driver.git", from: "1.1.0"),
    ],
    targets: [
        .target(name: "App", dependencies: [
            .product(name: "Vapor", package: "vapor"),
            .product(name: "Liquid", package: "liquid"),
            .product(name: "LiquidLocalDriver", package: "liquid-local-driver"),
            .product(name: "LiquidAwsS3Driver", package: "liquid-aws-s3-driver"),
        ]),
    ]
)

Driver configuration

import Liquid
import LiquidLocalDriver
import LiquidAwsS3Driver

public func configure(_ app: Application) throws {

    app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))

    // using the local driver
    app.fileStorages.use(.local(publicUrl: "http://localhost:8080/",
                                publicPath: app.directory.publicDirectory,
                                workDirectory: "assets"), as: .local)

    // using the AWS S3 driver (credentials must be configured as well)
    app.fileStorages.use(.awsS3(region: .uswest1, bucket: "testbucket"), as: .awsS3)

}

Basic usage example:

func testUpload(req: Request) -> EventLoopFuture<String> {
    let data: Data = //...
    let key = "path/to/my/file.txt"
    // the upload method returns the full url of the uploaded file
    return req.fs.upload(key: key, data: data)
    
    /// resolve public url based on a key
    // req.fs.resolve(key: myImageKey)

    /// delete file based on a key
    // req.fs.delete(key: myImageKey)
}

liquid's People

Contributors

tib avatar sadiq81 avatar

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.