API Reference

/nfs/file/:rootPath/:filePath

Create a file.
Only authorised requests can invoke the API

The API will create the file in the directory specified in the file path.

Request Header

Authorization: Bearer <TOKEN>
Content-Type: <Media type of the file being uploaded>
Content-Length: <Size of the file being uploaded>
Metadata: base64 String (optional)

Request body

Binary data of the file

Response

Ok
Unauthorized
Fields are missing

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) {
    return console.log('File created');
  }
  console.error('Failed to create file.', body);
};

var localFilePath = './api/sample.png'
var size = fs.statSync(localFilePath).size;
fs.createReadStream(localFilePath).pipe(request.post(endPoint, {
  headers: {
    'Content-Type': 'image/png',
    'Content-Length': size,
  },
  auth: {
    bearer: constants.token
  }
}, onResponse));
Language
Click Try It! to start a request and see the response here!