Small and simple node SDK to use the BunnyCDN Edge Storage API 🐰
npm install --save bunnycdn-storage-api-node-sdk
All function can be used with a promise or a callback as a response.
const fs = require('fs');
const storage = require('bunnycdn-storage-api-node-sdk')(API_STORAGE_KEY, API_STORAGE_ZONE);
const PATH = '/path/';
const FILE_NAME = 'superPicture.jpeg';
const FILE_BUFFER = fs.readFileSync('./' + FILE_NAME);
// Promise version
storage.putFile(PATH, FILE_NAME, FILE_BUFFER).then(data => {
console.log(data.toString()); // { "HttpCode" : 201, "Message" : "File uploaded." }
}).catch(err => {
console.log(err);
});
// callback version
storage.putFile(PATH, FILE_NAME, FILE_BUFFER, (err, resp, data) => {
console.log(data.toString()); // { "HttpCode" : 201, "Message" : "File uploaded." }
});
const storage = require('bunnycdn-storage-api-node-sdk')(API_STORAGE_KEY, API_STORAGE_ZONE);
const FILE_NAME = 'superPicture.jpeg'
// promise version
storage.getFile(PATH, FILE_NAME).then(data => {
// data is a buffer
}).catch(err => {
console.log(err);
});
// callback version
storage.getFile(PATH, FILE_NAME, (err, resp, data) => {
// data is a buffer
});
const storage = require('bunnycdn-storage-api-node-sdk')(API_STORAGE_KEY, API_STORAGE_ZONE);
// promise version
storage.deleteFile(PATH, FILE_NAME).then(data => {
console.log(data); // { HttpCode: 200, Message: 'File deleted successfuly.' }
}).catch(err => {
console.log(err);
});
// callback version
storage.deleteFile(PATH, FILE_NAME, (err, resp, data) => {
console.log(data); // { HttpCode: 200, Message: 'File deleted successfuly.' }
});
const storage = require('bunnycdn-storage-api-node-sdk')(API_STORAGE_KEY, API_STORAGE_ZONE);
storage.getFiles('/').then(data => {
console.log(data) // data is an array of objects, a list of files
}).catch(err => {
console.log(err);
});
storage.setStorageZone('newStorageZone');
storage.setStorageKey('newStorageKey');
storage.setBaseURL('https://');
$ npm run test
Contributions, issues and feature requests are welcome!
Give a ⭐️ if this project helped you!