Object Storage npm for IBM Cloud
npm install ibmcloud-objectstorage``ibmcloud-objectstorage` is a npm to manage your files with Node.js
In your project root directory:
`sh`
$ npm install ibmcloud-objectstorage -s
In your .js file, using the credentials you retrieved from the IBM Cloud console, fill the attributes inside `config``javascript`
var ObjectStorage = require('ibmcloud-objectstorage');
var config = {
provider: 'openstack',
useServiceCatalog: true,
useInternal: false,
keystoneAuthVersion: 'v3',
authUrl: '',
tenantId: '', //projectId from credentials
domainId: '',
username: '',
password: '',
region: '' //dallas or london region
};
var os = new ObjectStorage(config, "my-container");
ibmcloud-objectstorage uses the following functions, which are all promises:
`create` - Creates a container with the name you specified.`javascript`
os.create("my-container").then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})
`find` - Retrieves all the files inside the container you specified.`javascript`
os.find().then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})
`findByName` - Retrieves the file you specified, from the container.`javascript`
os.findByName('file.txt', './uploads/').then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})
`removeByName` - Deletes the file you specified, from the container.`javascript`
os.removeByName('file.txt').then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})
`insert` - Inserts the file you specified, on the container.`javascript``
os.insert('file.txt').then((response) => {
console.log(response);
})
.catch((err) => {
console.log(err);
})