New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

github-as-storage

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-as-storage

Free storage using github

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

This package is an experimental to use github as a storage service similar to AWS S3.

This is helpful for developers who want to work on small projects and pay for storage of file, instead going for some cloud providers. We can use the power of github storage and use it as conventional storage system.

This package uses @octokit/rest a Github's rest API client.

Bugs

If it doesn't work for you or you encounter any error. Please raise a issue with the details. GITHUB REPO

Prerequisites:

  • Github account
  • create an personal access token from github's settings page Token creation
  • A repository (where you want to store the files)

⚠️ Caution: Personal Access Token Permissions

> Be careful while creating a personal access token, allow only relevant permissions.

Installation:

  • Through npm install

    npm install github-as-storage 
    
  • Or in dependencies in package.json

     dependencies: { 
        "github-as-storage": "1.0.0", 
     }, 
    

Usage

Import the package as below

  const GithubStorageService = require('github-as-storage');

Each function need some parameters to be passed.

To perform these actions you need personal access token with access to that particular repo (to restrict access to other repos)

We are not storing the token for security concerns, so you need to pass it each and every time calling the below functions

Functionalities

Three functions implemented as of now:

  • Upload File:

    await GithubStorageService.uploadFile(envParams, filePath, fileBuffer) 
    
    • envParams :

        {
          accessToken: "Your Github Token",
          owner: "Your username (case sensitive)",
          repository: "Repository name",
          branch: "branch name you want to store"
        } 
      
    • filePath: exact path where you wanna store like which folder and filename (/samples/test/sample.pdf) It will store the sample.pdf inside test folder which is inside samples folder.

    • fileBuffer: buffer datatype of file you want to upload.

    • On successful upload: Will return the filepath where it is stored similar to s3Key.

          status: 'success',
          message: 'Image uploaded to GitHub repository successfully',
          response: {
            filePath,
          },
      
  • Delete File:

    await GithubStorageService.deleteFile(envParams, filePath) 
    
    • envParams: same as above mentioned
    • filPath: exact file path of the file (/samples/test/sample.pdf)
    • On successful deletion
            status: 'success',
            message: 'File deleted from GitHub repository successfully.',
      
  • Get File URL: To get the url for the file you want to use it to render it wherever you want to preview.

    await GithubStorageService.getUrl(envParams, filePath) 
    
    • will return the url for that filePath.

Support

Any one can feel free to improve this package functionality. visit the repo: Github as storage

Credits

Blog

FAQs

Package last updated on 12 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts