/nfs/file/:rootPath/:filePath

Read a file.
The file can be streamed in chunks and also fetched as partial content based on the range header specified in the request.
Only authorised requests can invoke this API.

Request Header

Authorization: Bearer <TOKEN>

Specifying range header

Partial content of the file can be obtained by specifying the range. The start and the end offset can be passed in the range header. This is an optional field, if not specified the entire file is streamed to the client.

Range: bytes 0-1000

Response

The API returns the metadata of the directory and the list of metadata of files and subdirectories.

Response Headers:
"content-range": "bytes 0-175786/175786"
"accept-ranges": "bytes"
"content-length": "175786"
"created-on": "2016-01-18T00:21:05.210Z"
"last-modified": "2016-01-18T00:21:05.212Z"
"content-type": "image/png"
"metadata": "RmlsZSBtZXRhZGF0YQ=="

Response Body:
Binary data
Unauthorized
Fields are missing
Invalid Range
Header FieldDescription
content-rangeRange being streamed / Total size.
created-onCreated time as ISO String.
last-modifiedLast modified time as ISO String.
metadataMetadata related to the file.

Examples

var request = require('request');
var fs = require('fs');
var endPoint = 'http://localhost:8100/nfs/file/app/pics/sample.png';

var onResponse = function(err, response, body) {
  if (err) {
    return console.error(err.message);
  }
  if (response.statusCode === 401) {
    return console.error('Failed to authorise');
  }
  if (response.statusCode === 200) {
    console.log(JSON.stringify(response.headers));
    return console.log('File downloaded');
  }
  console.error('Failed to download file.', body);
};

var filestream = fs.createWriteStream('./api/sample.png');// local path
request.get(endPoint, {  
  auth: {
    bearer: constants.token // pass the auth token
  }
}, onResponse).pipe(filestream);
Language
Click Try It! to start a request and see the response here!