Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adonis-filesystem

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-filesystem

This package allows uploading files to local fs, cloud storage, or another provider easy.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Adonis Filesystem

This package allows uploading files to local fs, cloud storage, or another provider easy.

NOTE This pacakge is currently in development. While the public API will be pretty stable, new features, connectors, and internal plumbing will change over time until v1.0.0 is reached

Installation

To install this addon:

npm install --save adonis-filesystem

Then update the bootstrap/app.js:

  • To the providers array add: adonis-filesystem/providers/FilesystemProvider
  • Optionally add File: 'AdonisFilesystem/Filesystem' to the aliases objects

Configuration

Add named config/filesystems.js with the following:

'use strict'

const Env = use('Env')
const Helpers = use('Helpers')

module.exports = {

  default: 'public',

  public: {
    driver: 'local',
    root: Helpers.publicPath('uploads'),
    options: {
      encoding: 'utf8'
    }
  },

  protected: {
    driver: 'local',
    root: Helpers.storagePath('app'),
    options: {
      encoding: 'utf8'
    }
  }

}

This will setup file connections to create files in public/uplodads using the public connection, and storage/app for the protected connections. Because the default use case is for image uploading, the public connection is set as a default, though this can be changed with the default parameter.

Use - Writing Files

To write to files use the put method on a Filesystem connection:

const File = use('File') // or use('AdonisFilesystem/Filesystem') if you did not install the alias

yield File.put('app.js', 'This is the contents of my file')

This will use the default connection to write a file named app.js with the text content 'This is the contents of my file'. The point of the Filesystem connection is that consuming applications do not worry about if files are local or on a cloud provider.

Use - Reading Files

To read to files use the get method on a Filesystem connection:

const File = use('File') // or use('AdonisFilesystem/Filesystem') if you did not install the alias

yield File.get('app.js')

This will use the default connection to read a file named app.js.

Use - Uploading Files

Uploading files can be a chore, by using the upload method, the Filesystem package will use streams to upload a file from request.file to the final upload destination:

const File = use('File') // or use('AdonisFilesystem/Filesystem') if you did not install the alias
const avatar = request.file('avatar', {
    maxSize: '2mb',
    allowedExtensions: ['jpg', 'png', 'jpeg']
})

yield File.upload(avatar.clientName(), avatar)

Use - Other Connectors

To use other connectors, use the connection method on the file instance. This will allow you to use a different connection than the default for a single file transaction:

const File = use('File') // or use('AdonisFilesystem/Filesystem') if you did not install the alias

yield File.connection('protected').put('secret.json', 'The silence will fall when the question is asked.')

License

This package is distributed under the MIT license.

FAQs

Package last updated on 01 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc