写个jsdelivr上传Github文件代码html
时间: 2024-01-29 10:05:00 浏览: 120
<!DOCTYPE html>
<html>
<head>
<title>JSDELIVR上传Github文件</title>
</head>
<body>
<h1>JSDELIVR上传Github文件</h1>
<form id="myForm">
<label for="fileInput">选择文件:</label>
<input type="file" id="fileInput" name="fileInput" required><br><br>
<label for="version">版本号:</label>
<input type="text" id="version" name="version" required><br><br>
<label for="vendor">厂商:</label>
<input type="text" id="vendor" name="vendor" required><br><br>
<label for="project">项目名称:</label>
<input type="text" id="project" name="project" required><br><br>
<label for="fileName">文件名:</label>
<input type="text" id="fileName" name="fileName" required><br><br>
<button type="submit" onclick="uploadFile()">上传文件</button>
</form>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
function uploadFile() {
const fileInput = document.getElementById('fileInput');
const version = document.getElementById('version').value;
const vendor = document.getElementById('vendor').value;
const project = document.getElementById('project').value;
const fileName = document.getElementById('fileName').value;
const formData = new FormData();
formData.append('file', fileInput.files[0]);
axios.post(`https://api.jsdelivr.com/gh/${vendor}/${project}@${version}/${fileName}`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
console.log(response);
alert("上传成功!");
})
.catch(error => {
console.log(error);
alert("上传失败!");
});
}
</script>
</body>
</html>
阅读全文