GithubHelp home page GithubHelp logo

adonis-storage's Introduction

Adonis Storage Provider

A storage provider for the Adonis framework.

This library provides an easy to use abstraction over multiple storage backends.

Install

npm install --save adonis-storage

Configure

Register it in bootstrap/app.js:

const providers = [
  ...
  'adonis-storage/providers/StorageProvider'
]

Also consider adding an alias to validation provider.

const aliases = {
  ...
  Storage: 'Adonis/Addons/Storage'
}

Add a configuration file in config/storage.js and copy over the example configurations.

Drivers

Currently, drivers exist for the local file system and Amazon S3.

  • fs

    File paths are rooted at ./storage. You can specify any path inside of the storage directory.

  • s3

    Files are stored in Amazon S3.

Usage

const Storage = use('Storage')

// returns true or false
yield Storage.exists('path/to/file')

// returns a buffer containing file contents
yield Storage.get('path/to/file')

// returns a ReadableStream of the file at path
yield Storage.getStream('path/to/file') 

// Store contents at path. If contents is an AdonisJS `file` object,
// this is treated as `putFile`
yield Storage.put('path/to/file', contents)

// Accepts a path and an AdonisJS `file` object.
// When calling `putFile` the name the file is stored as
// is automatically calculated as an md5 hash of the 
// file contents.
yield Storage.putFile('path/to/file/directory', contents)

// Accepts a path and an AdonisJS `file` object.
// Same as `putFile` but does not calculate the filename automatically.
// File will be stored at `path/to/file/directory/filename`
yield Storage.putFileAs('path/to/file/directory', contents, filename)

// Return the url or absolute file path for accessing the file
yield Storage.url('path/to/file')

License

Distributed under the MIT license.

Thanks

Special thanks to the creator(s) of AdonisJS for creating such a great framework.

adonis-storage's People

Contributors

nrempel avatar

Watchers

Edsel Serrano 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.