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

netstorageapi

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netstorageapi

Akamai Netstorage API for Node.js

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NetstorageAPI: Akamai Netstorage API for Node.js

npm package Build Status License

npm package

NetstorageAPI is Akamai Netstorage (File/Object Store) API for Node.js 4.0+ with native http module.

Table of Contents

Installation

To install Netstorage API with npm global:

$ npm install --global netstorageapi

or as a development dependency for your project:

$ npm install --save netstorageapi

Example

const Netstorage = require('netstorageapi')

// Defaults: SSL: false
const config = {
  hostname: 'astinobj-nsu.akamaihd.net',
  keyName: 'astinobj',
  key: 'xxxxxxxxxx',
  cpCode: '407617',
  ssl: false
}
// Don't expose KEY on your public repository.

const ns = new Netstorage(config)
const local_source = 'hello.txt'

// or `/${config.cpCode}/` will asume the destination filename is the same as the source
const netstorage_destination = `/${config.cpCode}/hello.txt`

ns.upload(local_source, netstorage_destination, (error, response, body) => {
  if (error) { // errors other than http response codes
    console.log(`Got error: ${error.message}`)
  }
  if (response.statusCode == 200) {
    console.log(body)
  }
}); 

// { message: 'Request Processed.' }

Methods

delete

↑ back to method list

  • Syntax:
ns.delete(NETSTORAGE_PATH, callback(err, response, body)) 
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the file, not the directory

dir

↑ back to method list

  • Syntax:
ns.dir(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path for the directory
    OPTIONSobjectJSON object containing options for the dir method
  • Valid Options:

  { path: '/your/path', 
    actions: { 
      max_entries: integer,
      start: '/start/path',
      end: '/end/path/',
      prefix: 'object-prefix',
      slash: 'both'
    }
  }

list

↑ back to method list

  • Syntax:
ns.list(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    OPTIONSobjectJSON object containing options for the list method
  • Valid Options:

  { path: '/your/path', 
    actions: { 
      max_entries: integer,
      end: '/end/path/'
    }
  }

download

↑ back to method list

  • Syntax:
ns.download(NETSTORAGE_SOURCE, LOCAL_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringPath to the file in NetStorage
    LOCAL_DESTINATIONstringLocation on the local host to write the downloaded file to (Optional value)

du

↑ back to method list

  • Syntax:
ns.du(NETSTORAGE_PATH, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory

mkdir

↑ back to method list

  • Syntax:
ns.mkdir(DIRECTORY_NAME, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    DIRECTORY_NAMEstringFull path to the directory you wish to create

mtime

↑ back to method list

  • Syntax:
ns.mtime(NETSTORAGE_PATH, UNIX_TIME, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory
    UNIX_TIMEintegerUnix time to set the mtime of the file to. Note that millisecond accuracy is not supported

quick_delete

↑ back to method list

  • Syntax:
ns.quick_delete(NETSTORAGE_DIR, callback(err, response, body)) // needs to be enabled on the CP Code
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the directory you wish to delete

rename

↑ back to method list

  • Syntax:
ns.rename(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_TARGETstringfull path to the original file/directory
    NETSTORAGE_DESTINATIONstringfull path to the renamed file/directory

rmdir

↑ back to method list

  • Syntax:
ns.rmdir(NETSTORAGE_DIR, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_DIRstringfull path to the empty object you wish to delete

stat

↑ back to method list

  • Syntax:
ns.stat(NETSTORAGE_PATH, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_PATHstringfull path to the file/directory you wish to stat

↑ back to method list

  • Syntax:
ns.symlink(NETSTORAGE_SOURCE, NETSTORAGE_TARGET, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    NETSTORAGE_SOURCEstringfull path to the original file
    NETSTORAGE_TARGETstringfull path of the new symlinked file to create

upload

↑ back to method list

  • Syntax:
ns.upload(LOCAL_SOURCE, NETSTORAGE_DESTINATION, callback(err, response, body))
  • Parameters:

    NameTypeDescription
    LOCAL_SOURCEstringPath to the local file you wish to upload
    NETSTORAGE_DESTINATIONstringPath to the location you wish to upload the file. Note that if you omit the actual filename, the source filename is used. You may only upload files using the API, not directories.

Testing

Unit tests for all of the above methods are executed via the test script. Prior to testing, create an api-config.json file in the test directory using the provided example for the required values. The excellent Mocha and ChaiJS libraries are used for all tests:

$ npm install --global mocha chai
$ npm test # use test/api-config.json

Author

Astin Choi (achoi@akamai.com)

License

Copyright 2016 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 28 Mar 2018

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