40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>FastAPI Example</title>
|
|
</head>
|
|
<body>
|
|
<h1>Hello, FastAPI!</h1>
|
|
<p>This is an example of loading an HTML file using FastAPI.</p>
|
|
uploadfile
|
|
<form id="uploadForm" enctype="multipart/form-data">
|
|
<input type="file" name="file" id="file">
|
|
<input type="submit" value="Upload File">
|
|
</form>
|
|
<script>
|
|
// 使用jQuery处理表单提交
|
|
$('#uploadForm').submit(function(e) {
|
|
e.preventDefault(); // 阻止表单默认提交行为
|
|
|
|
var formData = new FormData(this); // 创建FormData对象
|
|
|
|
$.ajax({
|
|
url: '/api/uploadfile/', // 上传文件的API端点
|
|
type: 'POST',
|
|
data: formData,
|
|
contentType: false, // 不设置内容类型
|
|
processData: false, // 不处理数据
|
|
success: function(response) {
|
|
// 文件上传成功后,下载文件
|
|
window.location.href = '/api/download/'; // 重定向到下载API端点
|
|
},
|
|
error: function(xhr, status, error) {
|
|
alert('Upload error: ' + error);
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |