This is a complete typescript rewirte of a official NodeJS package for Akamai Netstorage(netstorageapi) with added support of download and upload via buffer and async methods to avoid callback way. You can still use callback methods as well in same way.
- Installation
- Example
-
Methods
- delete
- deleteAsync
- dir
- dirAsync
- listAsync
- listAsync
- download
- downloadAsync
- downloadBuffer
- downloadBufferAsync
- du
- duAsync
- mkdir
- mkdirAsync
- mtime
- mtimeAsync
- quickDelete
- quickDeleteAsync
- rename
- renameAsync
- rmdir
- rmdirAsync
- stat
- statAsync
- symlink
- symlinkAsync
- upload
- uploadAsync
- uploadBuffer
- uploadBufferAsync
- Author
- License
To install Netstorage API for your project:
$ npm i ts-netstorageapi-akamai
const Netstorage = require('ts-netstorageapi-akamai')
OR
import Netstorage from "ts-netstorageapi-akamai";
// Defaults: SSL: false
// By default no proxy is set
const config = {
hostname: '*******.akamaihd.net',
keyName: 'DDDDDDDDDDDDDDDDDDDDDDDDDDDD',
key: 'xxxxxxxxxx',
cpCode: '407617',
ssl: false,
// proxy: 'https://yourproxyurl.com:port' // Optional
}
// 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)
}
});
// Async Way
let response: Promise<UploadResponse> = await ns.uploadAsync(local_source, netstorage_destination)
// { message: 'Request Processed.' }
- delete
- deleteAsync
- dir
- dirAsync
- listAsync
- listAsync
- download
- downloadAsync
- downloadBuffer
- downloadBufferAsync
- du
- duAsync
- mkdir
- mkdirAsync
- mtime
- mtimeAsync
- quickDelete
- quickDeleteAsync
- rename
- renameAsync
- rmdir
- rmdirAsync
- stat
- statAsync
- symlink
- symlinkAsync
- upload
- uploadAsync
- uploadBuffer
- uploadBufferAsync
- Syntax:
ns.delete(NETSTORAGE_PATH, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path for the file, not the directory
- Syntax:
ns.deleteAsync(NETSTORAGE_PATH)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path for the file, not the directory -
Response: Promise
- Syntax:
ns.dir(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path for the directory OPTIONS
object JSON 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'
}
}
- Syntax:
ns.dirAsync(NETSTORAGE_PATH|OPTIONS)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path for the directory OPTIONS
DirListOpts JSON 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'
}
}
- Response: Promise
- Syntax:
ns.list(NETSTORAGE_PATH|OPTIONS, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory OPTIONS
object JSON object containing options for the list method -
Valid Options:
{ path: '/your/path',
actions: {
max_entries: integer,
end: '/end/path/'
}
}
- Syntax:
ns.listAsync(NETSTORAGE_PATH|OPTIONS)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory OPTIONS
DirListOpts JSON object containing options for the list method -
Valid Options:
{ path: '/your/path',
actions: {
max_entries: integer,
end: '/end/path/'
}
}
- Response: Promise
- Syntax:
ns.download(NETSTORAGE_SOURCE, LOCAL_DESTINATION, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string Path to the file in NetStorage LOCAL_DESTINATION
string Location on the local host to write the downloaded file to (Optional value)
- Syntax:
ns.downloadAsync(NETSTORAGE_SOURCE, LOCAL_DESTINATION)
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string Path to the file in NetStorage LOCAL_DESTINATION
string Location on the local host to write the downloaded file to (Optional value) -
Response: Promise
- Syntax:
ns.downloadBuffer(NETSTORAGE_SOURCE, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string Path to the file in NetStorage
- Syntax:
ns.downloadBufferAsync(NETSTORAGE_SOURCE)
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string Path to the file in NetStorage -
Response: Promise
- Syntax:
ns.du(NETSTORAGE_PATH, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory
- Syntax:
ns.duAsync(NETSTORAGE_PATH)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory -
Response: Promise
- Syntax:
ns.mkdir(DIRECTORY_NAME, callback(err, response, body))
-
Parameters:
Name Type Description DIRECTORY_NAME
string Full path to the directory you wish to create
- Syntax:
ns.mkdirAsync(DIRECTORY_NAME)
-
Parameters:
Name Type Description DIRECTORY_NAME
string Full path to the directory you wish to create -
Response: Promise
- Syntax:
ns.mtime(NETSTORAGE_PATH, UNIX_TIME, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory UNIX_TIME
integer Unix time to set the mtime of the file to. Note that millisecond accuracy is not supported
- Syntax:
ns.mtimeAsync(NETSTORAGE_PATH, UNIX_TIME)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory UNIX_TIME
integer Unix time to set the mtime of the file to. Note that millisecond accuracy is not supported -
Response: Promise
- Syntax:
ns.quickDelete(NETSTORAGE_DIR, callback(err, response, body)) // needs to be enabled on the CP Code
-
Parameters:
Name Type Description NETSTORAGE_DIR
string full path to the directory you wish to delete
- Syntax:
ns.quickDeleteAsync(NETSTORAGE_DIR) // needs to be enabled on the CP Code
-
Parameters:
Name Type Description NETSTORAGE_DIR
string full path to the directory you wish to delete -
Response: Promise
- Syntax:
ns.rename(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_TARGET
string full path to the original file/directory NETSTORAGE_DESTINATION
string full path to the renamed file/directory
- Syntax:
ns.renameAsync(NETSTORAGE_TARGET, NETSTORAGE_DESTINATION)
-
Parameters:
Name Type Description NETSTORAGE_TARGET
string full path to the original file/directory NETSTORAGE_DESTINATION
string full path to the renamed file/directory -
Response: Promise
- Syntax:
ns.rmdir(NETSTORAGE_DIR, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_DIR
string full path to the empty object you wish to delete
- Syntax:
ns.rmdirAsync(NETSTORAGE_DIR)
-
Parameters:
Name Type Description NETSTORAGE_DIR
string full path to the empty object you wish to delete -
Response: Promise
- Syntax:
ns.stat(NETSTORAGE_PATH, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory you wish to stat
- Syntax:
ns.statAsync(NETSTORAGE_PATH)
-
Parameters:
Name Type Description NETSTORAGE_PATH
string full path to the file/directory you wish to stat -
Response: Promise
- Syntax:
ns.symlink(NETSTORAGE_SOURCE, NETSTORAGE_TARGET, callback(err, response, body))
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string full path to the original file NETSTORAGE_TARGET
string full path of the new symlinked file to create
- Syntax:
ns.symlinkAsync(NETSTORAGE_SOURCE, NETSTORAGE_TARGET)
-
Parameters:
Name Type Description NETSTORAGE_SOURCE
string full path to the original file NETSTORAGE_TARGET
string full path of the new symlinked file to create -
Response: Promise
- Syntax:
ns.upload(LOCAL_SOURCE, NETSTORAGE_DESTINATION, callback(err, response, body))
-
Parameters:
Name Type Description LOCAL_SOURCE
string Path to the local file you wish to upload NETSTORAGE_DESTINATION
string Path 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.
- Syntax:
ns.uploadAsync(LOCAL_SOURCE, NETSTORAGE_DESTINATION)
-
Parameters:
Name Type Description LOCAL_SOURCE
string Path to the local file you wish to upload NETSTORAGE_DESTINATION
string Path 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. -
Response: Promise
- Syntax:
ns.uploadBuffer(LocalBuffer, Basename, NETSTORAGE_DESTINATION, callback(err, response, body))
-
Parameters:
Name Type Description LocalBuffer
Buffer Buffer of the file you wish to upload Basename
string Filename you wish to keep for the uploaded file along with the extension. NETSTORAGE_DESTINATION
string Path to the location you wish to upload the file. You may only upload files using the API, not directories.
- Syntax:
ns.uploadBufferAsync(LOCAL_SOURCE, NETSTORAGE_DESTINATION)
-
Parameters:
Name Type Description LocalBuffer
Buffer Buffer of the file you wish to upload Basename
string Filename you wish to keep for the uploaded file along with the extension. NETSTORAGE_DESTINATION
string Path to the location you wish to upload the file. You may only upload files using the API, not directories. -
Response: Promise
Boffin Coders (info@boffincoders.com)
Thanks to Astin Choi (achoi@akamai.com) as well for writing the original lib.