Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

node-s3

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-s3

A simple Amazon S3 node.js integration

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

Node S3

A simple Amazon S3 node.js integration.

Build Status

Install

npm install node-s3

Usage

Initialization

First initialize the node-s3 module with a URI to your S3 bucket

var s3Url = 's3://key:secret@your_bucket.s3.amazonaws.com';
var s3 = require('node-s3')(s3Url);

It's important that the key/secret provided have write permissions to the bucket.

Alternatively initialize with an options object:

var options = {
  key: '...',
  secret: '...',
  bucket: '...',
  pathname: '/foo' // optional: prefix all S3 keys with this path
};
var s3 = require('node-s3')(options);

Uploading

Example 1: Upload a body

s3.put('/some-s3-key', body, callback);

Example 2: Pipe an incoming http request directly to S3

http.createServer(function (req, res) {
  var headers = {
    'Content-Length': req.headers['content-length']
  };
  var s3Req = s3.put('/some-s3-key', { headers: headers }, callback);
  req.pipe(s3Req);
}).listen(3000);

API

Common for all functions on the s3 object returned from the node-s3 constructor is that they take up to 3 arguemnts:

  • key - The requested S3 key (required). Will be concatinated with the optional pathname given upon initalization
  • body or options - Optional body or options hash
  • callback - Optional callback called with (err, response, body).

In any case, an instance of curly is returned which you among other things can pipe your data to.

Options or body:

The 2nd argument can either be a string, Buffer og an options hash. The first two should be rather self explanatory, and the options hash can be used to provide custom headers as well as a body to the S3 request:

var options = {
  headers: { ... },
  body: '...'
};

Functions:

  • s3.head(key, options || body, callback) - Perform a HEAD request
  • s3.get(key, options || body, callback) - Perform a GET request
  • s3.post(key, options || body, callback) - Perform a POST request
  • s3.put(key, options || body, callback) - Perform a PUT request
  • s3.del(key, options || body, callback) - Perform a DELETE request

License

MIT

Keywords

s3

FAQs

Package last updated on 07 Aug 2014

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