Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Laravel integrate GitHub to store files

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "Laravel how to integrate GitHub to store files", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Laravel how to integrate GitHub to store files" bar!

GitHub API introduction

API document: docs.github.com/en/rest

What you need to use is the very powerful GitHub API, where you only need to create or update the file content interface.

Create or update file contents

Request address: api.github.com/repos/ {owner} / {repo} / contents/ {path}

Request method: PUT

Parameters.

Name type location description acceptstringheader recommended to set to application/vnd.github.v3+jsonownerstringpath user name repostringpath warehouse name pathstringpath file storage path messagestringbody required-The commit messagecontentstringbody required-new file content, use Base64 encoding shastringbody if you want to update the file, it is required-the name of the blob SHAbranchstringbody branch of the file to be replaced-the default branch of the version library is usually the mastercommitterobjectbody submitter-the author of the authenticated user authorobjectbody file-the default is committer If committer is omitted, it is an authenticated user.

Properties of the committer object

Name description name (string) required-the name of the author or submitter who submitted it. If you omit name, you will receive the 422 status code email (string) required-email from the author or submitter of the submission. If you omit email, you will receive the 422 status code date (string)

Properties of the author object

Name description name (string) required-the name of the author or submitter who submitted it. If you omit name, you will receive the 422 status code email (string) required-email from the author or submitter of the submission. If you omit email, you will receive the 422 status code date (string)

Authentication

Officials offer three ways:

Basic authentication-username and password

OAuth3 Token-token

OAuth3 key/secret-client_id and client_secret (only queries are supported)

The second method is recommended.

Set up token

Settings > Developer settings > Personal access tokens > Generate new token

The generated token should be saved and displayed only once.

Create a warehouse

Be sure to make the repository public in order to be able to use jsDelivr CDN acceleration.

Using the GitHub warehouse as the drawing bed, the problem is that the speed of domestic access to GitHub is very slow, so we can use jsDelivr CDN to speed up the access. JsDelivr is a free and open source CDN solution, the platform is the first to connect Chinese mainland with overseas free CDN service, with an ICP license issued by the Chinese government, do not have to worry about China's firewall problems and affect their use. To use jsDelivr to accelerate access, you need to set the custom domain name to https://cdn.jsdelivr.net/gh/ user name / graph bed warehouse name.

Laravel code

Several configuration parameters need to be set, and it is recommended to put them in the .env file.

GITHUB_FILE_REPOSITORY=YOUR_REPOSITORYGITHUB_FILE_BRANCH=masterGITHUB_FILE_TOKEN=YOUR_TOKENGITHUB_FILE_PATH=YOUR_PATHGITHUB_FILE_NAME=1GITHUB_FILE_COMMIT_MESSAGE= "YOUR COMMIT MESSAGE"

Then create a profile under config, and I create a github-file.php profile

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report