浏览器端通过js上传文件到github的api上示例代码

代码语言:html

所属分类:上传

代码描述:浏览器端通过js上传文件到github的api上示例代码

代码标签: 浏览器 通过 js 上传 文件 github api 示例 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
  <title>GitHub API File Upload</title>
</head>
<body>

<input type="file" id="fileInput" />
<button id="uploadButton">Upload</button>

<script>
document.getElementById('uploadButton').addEventListener('click', async () => {
  const token = '';//你的tokems

  const repo = 'bfw/test';
  

  const fileInput = document.getElementById('fileInput');
  
  const file = fileInput.files[0];
  if (!file) {
    alert('Please select a file.');
    return;
  }
  
  const reader = new FileReader();
  reader.onload = async (event) => {
    const fileContent = event.target.result.split(',')[1];
    
    const apiUrl = `https://api.github.com/repos/${repo}/contents/${file.name}`;
  .........完整代码请登录后点击上方下载按钮下载查看

网友评论0