<!DOCTYPE html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
<head>
|
<title>上传接口测试</title>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<script src="js/jquery.1.12.4.js"></script>
|
<script>
|
var url = "http://127.0.0.1:12316/";
|
var token = "a5cca7ad-bfe6-43bd-aa62-e19f2ffac6bd";
|
|
$(function () {
|
$("#tokenSpan").html(token);
|
});
|
|
function ajax(url, type, data, dataType, contentType, fn) {
|
$.ajax({
|
url: url,
|
type: type,
|
data: data,
|
dataType: dataType || "json", // html、json、jsonp、script、text
|
contentType: contentType || "application/json", // "application/x-www-form-urlencoded"
|
success: function (data) {
|
fn(data);
|
},
|
error: function (e) {
|
console.error(e);
|
fn();
|
}
|
});
|
}
|
|
function getUrl(method) {
|
return url + method + "?token=" + token;
|
}
|
|
function downloadMap(guid) {
|
var a = document.createElement('a'); // 创建a标签
|
a.style.display = 'none'; // 设置不可见
|
a.href = getUrl("mark/downloadFile") + "&guid=" + guid;
|
|
document.body.appendChild(a); // 加入
|
a.click(); // 触发点击
|
document.body.removeChild(a); // 释放
|
}
|
|
// 上传数据
|
function uploadData() {
|
var formData = new FormData();
|
var fs = document.getElementById("file1");
|
for (var i = 0, c = fs.files.length; i < c; i++) {
|
formData.append(fs.files[i].name, fs.files[i]); // fs.files[i].name,file
|
}
|
formData.append("name", "测试");
|
formData.append("dirid", "10");
|
formData.append("depid", "1");
|
formData.append("verid", "1");
|
formData.append("type", "gdb");
|
formData.append("cs", "CGCS 2000");
|
formData.append("scale", "1:1000");
|
formData.append("resolution", "0.5m");
|
formData.append("gather", "2022-10-03 15:00:00");
|
formData.append("descr", "");
|
|
$.ajax(getUrl("uploader/uploadData"), {
|
type: "post",
|
data: formData,
|
async: true,
|
cache: false,
|
processData: false,
|
contentType: false,
|
success: function (rs) {
|
alert("code = " + rs.code + ", msg = " + rs.msg + ", result = " + rs.result);
|
console.log(rs);
|
},
|
error: function (e) {
|
console.error(e);
|
}
|
});
|
}
|
|
function uploadFiles() {
|
var url = getUrl("uploader/");
|
}
|
</script>
|
</head>
|
<body>
|
<form id="upForm" name="upForm" method="post" enctype="multipart/form-data" action="http://127.0.0.1:12316/file/upload">
|
当前令牌:<span id="tokenSpan"></span><br />
|
|
请选择文件:
|
<input id="file1" name="file1" type="file" multiple="multiple" />
|
<input id="btnUp" value="上传文件" type="button" onclick="uploadFiles();" />
|
</form>
|
<br />
|
<br />
|
</body>
|
</html>
|