mirror of
https://github.com/axios/axios.git
synced 2026-04-11 02:11:50 +08:00
* feat: implement prettier and fix all issues * fix: failing tests * fix: implement feedback from codel, ai etc * chore: dont throw in trim function Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: incorrect fix --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
53 lines
1.6 KiB
HTML
53 lines
1.6 KiB
HTML
<!doctype html>
|
|
<html>
|
|
|
|
<head>
|
|
<title>axios - file upload example</title>
|
|
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
|
|
</head>
|
|
|
|
<body class="container">
|
|
<h1>file upload</h1>
|
|
|
|
<form role="form" class="form" onsubmit="return false;">
|
|
<div class="form-group">
|
|
<label for="file">File</label>
|
|
<input id="file" type="file" class="form-control" />
|
|
</div>
|
|
<button id="upload" type="button" class="btn btn-primary">Upload</button>
|
|
</form>
|
|
|
|
<div id="output" class="container"></div>
|
|
|
|
<script src="/axios.min.js"></script>
|
|
<script>
|
|
(function () {
|
|
var output = document.getElementById('output');
|
|
document.getElementById('upload').onclick = function () {
|
|
var data = new FormData();
|
|
data.append('foo', 'bar');
|
|
data.append('file', document.getElementById('file').files[0]);
|
|
|
|
var config = {
|
|
onUploadProgress: function (progressEvent) {
|
|
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
output.className = 'container';
|
|
output.textContent = 'Upload progress: ' + percentCompleted + '%';
|
|
}
|
|
};
|
|
|
|
axios.put('/upload/server', data, config)
|
|
.then(function (res) {
|
|
output.className = 'container';
|
|
output.textContent = res.data;
|
|
})
|
|
.catch(function (err) {
|
|
output.className = 'container text-danger';
|
|
output.textContent = err.message;
|
|
});
|
|
};
|
|
})();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |