0.0.14 • Published 2 years ago

@appstrax/storage v0.0.14

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

@appstrax/storage

This is a simple file storage storage service, which allows you to easily integrate appstrax storage into your web applications.

Getting Started

Create your Appstrax Storage API here: https://codecapsules.io/.

Installation

npm install @appstrax/storage --save

Setup

Initialize the storage library:

// import the storage library
import { storage } from '@appstrax/storage';

// initialize the storage service
const apiUrl = 'YOUR API URL HERE'; // eg. appstrax-storage-api-snidtu.codecapsules.co.za
storage.init(apiUrl);

Upload Files:

Add the following file input and button in your html view:

<input 
  id="fileInput" 
  type="file" 
  style="display: none" 
  onchange="onFileSelected(this)" 
/>
<button onclick="fileInput.click()">Upload file</button>

Create a function called onFileSelected your the corresponding javascript

import { storage } from '@appstrax/storage';

async function onFileSelected(input) {
  if (input.files && input.files.length) {
    const file = input.files[0];
    const filePath = 'images/';
    try {
      const result = await storage.uploadFile(file, filePath);

      // use the downloadUrl to access your file.
      console.log(result.downloadUrl); 
      /* Eg. 
        <img id="image" />
        ...
        document.getElementById('image').src = result.downloadUrl;
      */

      input.value = '';
    } catch (err: any) {
      // handle error
    }
  }
}

If the file uploaded is stream-able IE a video or audio file. Add &stream=true to the file's downloadUrl. This will result in a better experience when using <video> and <audio> tags.

To force the file to download when the link is opened in a browser, add &download=true to the file's downloadUrl.

Delete An Uploaded File:

import { storage } from '@appstrax/storage';

try {
  const downloadUrl = 'YOUR DOWNLOAD URL HERE';
  await storage.deleteFile(downloadUrl);
} catch (err) {
    // handle error
}
0.0.13

2 years ago

0.0.14

2 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago