Storage driver using Local filesystem for Vapor 3.
This package is based on StorageKit
Add this project to the Package.swift dependencies of your Vapor project:
.package(url: "https://github.com/gperdomor/local-storage.git", from: "0.1.0")After you've added the LocalStorage package to your project, setting the provider up in code is easy.
First, register the LocalStorageProvider in your `configure.swift' file.
public func configure(
_ config: inout Config,
_ env: inout Environment,
_ services: inout Services
) throws {
/// Register providers first
try services.register(LocalStorageProvider())
// or whatever directory you want
let rootDirectory = DirectoryConfig.detect().workDir
// Add the adapter
var adapters = AdapterConfig()
adapters.add(adapter: try LocalAdapter(rootDirectory: URL(fileURLWithPath: "\(rootDirectory)Public/buckets"), create: true), as: .local)
services.register(adapters)
}struct BucketRequest: Content {
let name: String
}
func create(_ req: Request, body: BucketRequest) throws -> Future<HTTPStatus> {
let name = body.name
return req.withStorage(to: AdapterIdentifier<LocalAdapter>.local) { storage in
return try storage.create(bucket: name, on: req).transform(to: HTTPStatus.ok)
}
}This package is developed and maintained by Gustavo Perdomo
LocalStorage is released under the MIT License.