Client-SDK for nexusdocs-server
npm install nexusdocs-client
- Client
-
Class presenting NexusDocs client instance
- Namespace
-
Class presenting NexusDocs namespace instance
module.exports(options) ⇒ Client
⏏
Create a NexusDocs client instance
Kind: Exported function
See: new Client()
Param | Type | Description |
---|---|---|
options | ServerOptions |
Server options, see ServerOptions |
Example
Create a client
const createClient = require('nexusdocs-client');
// Object style server options:
const client = createClient({
hostname: '192.168.1.6',
port: 4001,
apiKey: 'MY_API_KEY',
apiSecret: 'MY_API_SECRET',
});
// URL style server options:
const client = createClient('http://MY_API_KEY:MY_API_SECRET@192.168.1.6:4001/api');
Class presenting NexusDocs client instance
Kind: global class
-
Client
- new Client(options)
- instance
-
inner
-
~ServerOptions :
object
-
~ServerOptions :
Creates an instance of NDS Client.
Param | Type | Description |
---|---|---|
options |
ServerOptions | string
|
Server options, see ServerOptions |
Example
You can pass a URL sting instead of a config object:
http://<clientKey>:<clientSecret>@<hostname>:<port><endPoint>
client.getNamespace(name, [options]) ⇒ Namespace
Get namespace instance
Kind: instance method of Client
Returns: Namespace
- Namespace instance
Param | Type | Description |
---|---|---|
name | string |
The name |
[options] | object |
Additional options |
Server options
Kind: inner typedef of Client
Properties
Name | Type | Default | Description |
---|---|---|---|
clientKey | string |
NDS API key | |
clientSecret | string |
NDS API secret | |
[hostname] | string |
"127.0.0.1" |
hostname |
[secure] | boolean |
false |
Whether to use HTTPS |
[port] | number |
4000 |
Server Port |
[endPoint] | string |
"/api" |
API endpoint |
[defaultUrlExpires] | number |
Default expires seconds | |
[defaultRequestExpires] | number |
Default expires seconds |
Class presenting NexusDocs namespace instance
Kind: global class
-
Namespace
- new Namespace(client, name, options)
-
instance
-
.getUploadUrl([options]) ⇒
string
-
.getDownloadUrl(fileId, [options]) ⇒
string
-
.getConvertedUrl(fileId, converting, [options]) ⇒
string
-
.upload(Buffer|ReadableStream, [options]) ⇒
Promise
-
.openUploadStream([options]) ⇒
WritableStream
-
.uploadFromLocal(filePath, options) ⇒
Promise
-
.openDownloadStream(fileId, [options]) ⇒
ReadableStream
-
.downloadToLocal(fileId, filePath, [options]) ⇒
Promise
-
.getFileInfo(fileId) ⇒
Promise
-
.delete(fileId) ⇒
Promise
-
.truncate() ⇒
Promise
-
.createArchive(files) ⇒
Promise
- .getArchiveUrl(files, options)
-
.getUploadUrl([options]) ⇒
-
inner
-
~RequestOptions :
object
-
~UploadOptions :
object
-
~DownloadOptions :
object
-
~FileId :
string
-
~ImageInfo :
object
-
~ZipFileEntry :
object
-
~ZipInfo :
object
-
~FileInfo :
object
-
~ConvertingOptions :
object
-
~RequestOptions :
Namespace Class constructor
Param | Type | Description |
---|---|---|
client | Client |
NDS Client instance |
name | string |
The name of namespace |
options | object |
Example
Create a namespace instance
const namespace = client.getNamespace('a.name.space');
Get URL for upload
Kind: instance method of Namespace
Returns: string
- URL for upload
Param | Type | Description |
---|---|---|
[options] | RequestOptions |
Additional options, see RequestOptions |
[options.resumable] | boolean |
If upload with resumbable.js |
[options.expires] | date |
Timestamp the Request will available before |
Get file URL for view or download
Kind: instance method of Namespace
Returns: string
- file URL
Param | Type | Description |
---|---|---|
fileId | FileId |
File identifier, see FileId |
[options] | DownloadOptions |
Additional options, see DownloadOptions |
Get the converted file URL for view or download
Kind: instance method of Namespace
Returns: string
- The converted file URL
Param | Type | Description |
---|---|---|
fileId | FileId |
File identifier, see FileId |
converting | ConvertingOptions |
Converting options, see ConvertingOptions |
[options] | DownloadOptions |
Additional options, see DownloadOptions |
Upload file from Buffer, ReadableStream
Kind: instance method of Namespace
Fulfil: object
File info when uploading is finished
Reject: any
Request error
Param | Type | Description |
---|---|---|
Buffer | ReadableStream | data |
[options] | UploadOptions |
Additional options, see UploadOptions |
Get upload stream
Kind: instance method of Namespace
Returns: WritableStream
- Writable stream for upload
Param | Type | Description |
---|---|---|
[options] | UploadOptions |
Additional options, see UploadOptions |
[options.stream] | ReadableStream |
Provide readable stream directly |
Upload a file from local file-system
Kind: instance method of Namespace
Fulfil: FileInfo
File info when uploading is finished
Reject: any
Request error
Param | Type | Description |
---|---|---|
filePath | string |
The path of file will be uploaded |
options | UploadOptions |
Upload options |
Get a readable stream for download
Kind: instance method of Namespace
Returns: ReadableStream
- - the readable stream
Param | Type | Description |
---|---|---|
fileId | FileId |
The file needed to download later, see FileId |
[options] | RequestOptions |
Additional options, see RequestOptions |
Download a file to local file-system
Kind: instance method of Namespace
Fulfil: any
Download finished
Param | Type | Description |
---|---|---|
fileId | FileId |
The file id, see FileId |
filePath | string |
The path of file will be saved |
[options] | RequestOptions |
Additional options, see RequestOptions |
Get file information
Kind: instance method of Namespace
Fulfil: FileInfo
file information
Param | Type |
---|---|
fileId | FileId |
Delete a file on the server
Kind: instance method of Namespace
Fulfil: object
When deletion is finished
Reject: any
When a error occur
Param | Type | Description |
---|---|---|
fileId | FileId |
The file to be deleted, see FileId |
Delete all files in this namespace
Kind: instance method of Namespace
Create an archive
Kind: instance method of Namespace
Param | Type | Description |
---|---|---|
files | Array.<FileId> |
file id array |
Archive files then return download URL
Kind: instance method of Namespace
Param | Type | Description |
---|---|---|
files | Array.<FileId> |
file id array, see FileId |
options | RequestOptions |
RequestOptions, see RequestOptions |
Request options for request, some properties are added for additional use, see specified method
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
method | string |
HTTP method of the request |
url | string |
Path of the request, or full url |
[body] | string |
Entire body for PATCH, PUT, POST or DELETE, json must be true and only plain object is allowed |
[json] | boolean |
Set to true when providing body
|
[expires] |
number | date
|
Expires time in second, timestamp or Date object, the request will be invalid after this timestamp |
[signature] | object |
Additional signature data besides method , url , expires
|
Upload request options
Kind: inner typedef of Namespace
Extends: RequestOptions
Properties
Name | Type | Description |
---|---|---|
[fileId] | FileId |
Specify fileId, see FileId |
[filename] | string |
Provide filename |
[md5] | string |
MD5 hash of the file if available |
[contentType] | string |
Provide content-type for download |
[knownLength] | number |
Provide stream total length if available |
Download options
Kind: inner typedef of Namespace
Extends: RequestOptions
Properties
Name | Type | Default | Description |
---|---|---|---|
[origin] | boolean |
false |
Download from the origin provider |
[download] | boolean |
false |
Download with the original filename |
[filename] | string |
Download with new filename, this will set contentType & contentDisposition | |
[response] | object |
Overwrite response header | |
[response.contentType] | string |
Overwrite Content-Type | |
[response.contentDisposition] | string |
Overwrite Content-Disposition |
File identifier
Kind: inner typedef of Namespace
Example
Example file id: `e5ac71cf-a0f0-46b5-9070-268ae97bb769`
Image file info
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
width | number |
Image width |
height | number |
Image height |
type | number |
Image type, e.g. jpeg, png, gif |
thumbnailUrl | string |
Image thumbnail data-url |
Zip file entry
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
path | string |
Relative path to zip archive |
size | number |
Stored size |
lastModified | date |
Last modified date |
Zip file info
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
entries | Array.<ZipFileEntry> |
files |
File information
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
namespace | string |
Namespace file is stored in |
md5 | string |
MD5 hash string |
contentType | string |
File content type |
size | number |
File total length |
metadata | object |
Additional information |
[metadata.image] | ImageInfo |
Metadata for image files |
[metadata.zip] | ZipInfo |
Zip file entries |
File converting options
Kind: inner typedef of Namespace
Properties
Name | Type | Description |
---|---|---|
format | string |
The output format, documents : pdf , image : gif , jpeg , png , webp , tiff
|
[resize] | string |
For image , resize the image <width>x<height>{%}{@}{!}{<}{>} please check GraphicsMagick. notice: only {!}{>}{^} are available when the server is using ImageSharpConverter
|
[rotate] |
string | number
|
For image , rotate the image by angle {auto}{90}{180}{270} , if auto is set, the angle will be detected by gravity from EXIF |
[quality] | number |
Forimage , set the output image quality 0 - 100, available for format jpeg , tiff , webp
|
Example
Get a thumbnail of size 32px
{
format: 'jpeg',
resize: '32x32',
rotate: 'auto'
}
Example
Get a pdf version of a document
{
format: 'pdf',
}
MIT