Git Product home page Git Product logo

strapi-provider-upload-github's Introduction

strapi-provider-upload-github

Github/Github-Pages provider for Strapi CMS file upload.

Installation

npm install strapi-provider-upload-github

Prerequisite

  • Make sure git is installed and accessable at runtime on server.
  • Avoid using code repo for uploading assets.
  • Given empty branch should not contain any files.

Config

./extensions/upload/config/config.json

{
      "provider": "github",
      "providerOptions": {
          "repo": "https://github.com/user-name/site-assets",
          "user": "user-name",
          "token": "***token***",
          "emptyBranch": "upload",
          "baseBranch": "master",
          "publicUrl": "https://user-name.github.io/site-assets",
          "sizeLimit": 1000000
      },
}

Parameters

  • repo - github repo link
  • user - github user name
  • token - github user token (Creating a personal access token - GitHub Docs)
  • emptyBranch - branch name with no files (Empty branch used to auto merge uploaded files without any conflicts).
  • baseBranch - branch name pointed to github pages.
  • publicUrl - github pages public url. (alternatively you can use public urls from vercel, surge, netlify)
  • sizeLimit - upload file size limit.

Resources

Links

strapi-provider-upload-github's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ph4ntomiki

strapi-provider-upload-github's Issues

Use Contents API to add a file

Hey, thanks for the plugin, it was a big in inspiration for me to try something similar.

I found the setup a bit complicated, why do we need an additional empty branch etc. Have you considered using Contents API to add files to the repository?

Contents API reference

I played with it and it looks promising:

const { Octokit } = require('@octokit/core')

octokit = new Octokit({
  auth: personalAccessToken
})

async upload(file) {
  // Find some unique file name for the uploaded file
  const filePath = generateUploadFileName('content/', file)

  const response = await octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
    owner,
    repo,
    path: filePath,
    message: `Add ${filePath}`,
    content: file.buffer.toString('base64')
  })

  file.url = response.data.content.download_url
}

You may not be able to just rely on download_url field if the repo is private, but the github pages link can be provided instead in such cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.