Coder Social home page Coder Social logo

folders-aws's Introduction

Folders

This node.js package implements the folders.io synthetic file system.

This Folders Module is based on a amazon web services, Module can be installed via "npm install folders-aws".

Example:

Installation (use --save to save to package.json)

npm install folders-aws

##S3

Basic Usage

Configuration

In order to access aws services , you must provide credentials . There are 2 ways to provide them

Credentials from Environment Variables

You can set environment variables to provide sdk credentials . This means that if you properly set your environment variables, you do not need to manage credentials in your application at all.

The keys names must be as follows:

export AWS_ACCESS_KEY_ID =  "your access key id" 
export AWS_SECRET_ACCESS_KEY = "your secreet access key "

Credentials in the constructor

This means you can pass credentials directly to the folders-aws constructor object as mentioned in next section .This method is not recommended

if both 'Credentials from Disk' 'and 'Credentials from Environment Variables' are set then former takes precedence over later

Constructor

Provider constructor, could pass the special option/param in the config param.

var FoldersAws = require('folders-aws');

var config = {
           accessKeyId: "Amazon Acess Id" (String),
           secretAccessKey : "Amazon access key" (String),
		   service : ['S3','EC2'],
		   region: ['us-west-2','us-east-1'],
		   bucket : ['mybucket1','mybucket2'],
		   partSize: 10 *1024*1024, // (optional) partsize  default is 5 MB 
 		   queueSize:5 // (optional) concurrency level
};

var aws = new FoldersAws("localhost-aws", config);

It is not recommended to provide 'accessKeyId' and 'secretAccessKey' in the constructor directly and use other methods as mentioned in configuration section to do this.

###ls

/**
 * @param uri, the uri to ls
 * @param cb, callback function. 
 * ls(uri,cb)
 */
 
aws.ls('s3/us-west-2/mybcuket1/video/', function(err,data) {
        console.log("Folder listing", data);
});

###cat

/**
 * @param uri, the file uri to cat 
 * @param cb, callback function.
 * cat(uri,cb) 
 */

aws.cat('s3/us-west-2/mybcuket1/video/movie.wmv', function(err,result) {
        console.log("Read Stream ", result.stream);
});

write

/**
 * @param path, string, the path 
 * @param data, the input data, 'stream.Readable' or 'Buffer'
 * @param cb, the callback function
 * write(path,data,cb)
 */

var writeData = getWriteStreamSomeHow('some_movie.mp4');

aws.write('s3/us-west-2/mybcuket1/video/some_movie.mp4',writeData, function(err,result) {
        console.log("Write status ", result);
});

unlink

/**
 * @param path, string, the path 
 * @param cb, the callback function
 * unlink(path,cb)
 */

aws.unlink('/path1/path2/some_movie.mp4', function(err) {
        
		if (err){
			console.log("Got error ",err);
		}
});

rmdir

/**
 * @param path, string, the path 
 * @param cb, the callback function
 * rmdir(path,cb)
 */

aws.rmdir('/path1/path2/', function(err) {
        
		if (err){
			console.log("Got error ",err);
		}
});

### mkdir

```js

/**
 * @param path, string, the path 
 * @param cb, the callback function
 * mkdir(path,cb)
 */

aws.mkdir('/path1/path2/', function(err) {
        
		if (err){
			console.log("Got error ",err);
		}
});

'service' , 'region' and 'bucket' attributes  in 'config' can be 'String' or 'Array' or 'Optional (undefined)'. 

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.