0.0.4 • Published 4 years ago

@appstrax/storage-admin v0.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

@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
});