|
|
<!DOCTYPE html>
|
|
|
<html>
|
|
|
<head>
|
|
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
|
|
<meta content="utf-8" http-equiv="encoding" />
|
|
|
<script src="http://code.jquery.com/jquery-1.9.1.min.js">
|
|
|
</script>
|
|
|
<title>
|
|
|
前台上传文件
|
|
|
</title>
|
|
|
<script type="text/javascript">
|
|
|
var id;
|
|
|
function postData() {
|
|
|
//获取文件名
|
|
|
var filename = getFileName($("#uploadfile").val());
|
|
|
|
|
|
$.ajax({
|
|
|
url: '/tools/minioRelate/getPostPolicyInfo?filename=' + filename, //获取上传文件时用到的相关信息
|
|
|
type: 'GET',
|
|
|
async: false,
|
|
|
success: function(res) {
|
|
|
|
|
|
if (res.success) {
|
|
|
var formData = new FormData();
|
|
|
|
|
|
formData.append("file", $("#uploadfile")[0].files[0]);
|
|
|
formData.append("policy", res.policy);
|
|
|
formData.append("x-amz-algorithm", res.x_amz_algorithm);
|
|
|
formData.append("x-amz-credential", res.x_amz_credential);
|
|
|
formData.append("x-amz-date", res.x_amz_date);
|
|
|
formData.append("x-amz-signature", res.x_amz_signature);
|
|
|
formData.append("bucket", res.bucket);
|
|
|
formData.append("key", res.key);
|
|
|
|
|
|
id = res.id
|
|
|
|
|
|
//正式上传文件
|
|
|
$.ajax({
|
|
|
url: res.url,
|
|
|
type: 'POST',
|
|
|
async: false,
|
|
|
data: formData,
|
|
|
contentType: false,
|
|
|
processData: false,
|
|
|
mimeType: 'multipart/form-data',
|
|
|
success: function() {
|
|
|
//上传成功后调用接口,后台将上传文件的相关信息进行记录
|
|
|
$.ajax({
|
|
|
url: '/tools/minioRelate/saveFileInfo?id=' + id + "&systemid=gl",
|
|
|
type: 'GET',
|
|
|
async: false,
|
|
|
success: function() {
|
|
|
alert("上传成功!");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
alert(res.info);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//获取预览地址
|
|
|
function preview()
|
|
|
{
|
|
|
$.ajax({
|
|
|
url: '/tools/minioRelate/generatePreviewUrl?id=' + id,
|
|
|
type: 'GET',
|
|
|
async: false,
|
|
|
success: function(res) {
|
|
|
$("#preview").attr('src', res.url);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//获取文件名
|
|
|
function getFileName(o) {
|
|
|
var pos = o.lastIndexOf("\\");
|
|
|
return o.substring(pos + 1);
|
|
|
}
|
|
|
</script>
|
|
|
</head>
|
|
|
<body>
|
|
|
<input type="file" name="uploadfile" id="uploadfile" value="" />
|
|
|
<input type="button" onclick="postData();" value="上传" name="" />
|
|
|
<input type="button" onclick="preview();" value="查看刚上传文件的预览" name="" />
|
|
|
<br />
|
|
|
<iframe id="preview" width="800" height="600"></iframe>
|
|
|
</body>
|
|
|
|
|
|
</html> |