@appstrax/storage-admin
v0.0.4
Published
The @appstrax/storage-admin service side javascript library
Downloads
8
Readme
@appstrax/storage-admin
This library integrates with the Appstrax storage API. The is meant to be used in a nodejs application.
Getting Started
Create your Appstrax Storage API here: https://codecapsules.io/.
Installation
npm install @appstrax/storage-admin --save
Setup
Initialize the storage
library:
// import the storage library
import { storage } from '@appstrax/storage-admin';
// initialize the storage service
const apiUrl = 'YOUR API URL HERE'; // eg. appstrax-storage-api-snidtu.codecapsules.co.za
storage.init(apiUrl);
Upload File:
To upload a file, read the file with fs, and upload with storage.
import fs from 'fs';
import { storage } from '@appstrax/storage';
const buffer: Buffer = fs.readFileSync(__dirname + '/file.txt');
storage.uploadFile(buffer, 'filename.txt', '/text-files')
.then(res => {
const downloadUrl = res.downloadUrl;
})
.catch(err => {
// unable to upload file
});
Delete File:
import { storage } from '@appstrax/storage';
const downloadUrl = '<DOWNLOAD_URL_HERE>';
storage.deleteFile(downloadUrl)
.then(() => {
// file successfully deleted
})
.catch(err => {
// unable to deleted file
});