Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github-picbed

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-picbed

Upload file to github and Get Url

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

GitHub Picture Bed

A picture bed based on GitHub. Provide an HTTP file service through Pages. Upload images using the GitHub API.

Installation

npm install github-picbed

Usage

const github = require('github-picbed')({
    token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    repository: 'https://github.com/imlinhanchao/upload-file'
})
const path = require('path');

router.post('/upload', async (req, res, next) => {
    let data = req.files[0].buffer;
    let extname = path.extname(req.files[0].originalname);
    let upload = await github.upload({ data, extname })
    res.json(upload);
})

Preparation

  1. You need to create an access token in GitHub. Select only repo for the select scopes.
  2. Create a repository use to upload files. And then enable GitHub Pages.

Functions

Config Upload Options

async function config({ token, repository });
Parameter Object
keydescription
tokenYour GitHub access token.
repositoryYour repository use to upload files.

Check Initialize State

async function isInitialized();
Return Value

bool - true means finish initialize.

Upload file

async function upload({ data, extname, filename });
Parameter Object
keydescription
dataThe file path that you want to upload or the buffer of file.
extnameThe extname of file. You must set this key if the data is buffer.
filenameThe filename that you want to upload.(Options)
Return Object
keydescription
filenameThe filename that was eventually uploaded.
urlAccess URL.

Notice

After configuring the GitHub repository address and access token, it takes about 1 second to get the information of GitHub Pages. Therefore, please do not upload immediately after configuration. You can use isInitialized to check if initialization has been completed. Or use await to wait for the configuration to complete.

Keywords

FAQs

Package last updated on 15 May 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc