哎 写了个视频上传然后编辑页死活写不出来了 没有办法 找了个大哥嗯记录一下
就上一个添加的图吧
html
<video style="height:350px;width: 470px;margin-left: 190px" src="" id="video0" controls="controls" autoplay="autoplay"></video>
<input class="form-control" type="file" style="height:auto;margin-left: 188px" id="file" onchange="uploadpic()"/>
js
$("#file").change(function () {
var objUrl = getObjectURL(this.files[0]);
console.log("objUrl = " + objUrl);
if (objUrl) {
$("#video0").attr("src", objUrl);
}
});
function getObjectURL(file) {
var url = null;
if (window.createObjectURL != undefined) { // basic
url = window.createObjectURL(file);
} else if (window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
return url;
}
function uploadpic(){
var formData = new FormData();
var file = document.getElementById('file').files[0];
formData.append("file", file);
$.ajax({
url: prefix + "/后台地址",
type: "post",
// data:formData,
data:formData,
processData: false,//用于对data参数进行序列化处理 这里必须false
contentType: false, //必须*/
success: function (data) {
var obj = data;
$("#courseUrl").attr("value",obj);
}
});
}
controller
@PostMapping("/ZipUpload")
@ResponseBody
public String importSqlLite(MultipartFile file) throws Exception {
String fileName = file.getOriginalFilename();
fileName = FileUtil.renameToUUID(fileName);
Date date = new Date();
FileDO sysFile = new FileDO(FileType.fileType(fileName), "/file/CourseUpload/"+ new SimpleDateFormat("yyyy/MM/dd/").format(date) + fileName, new Date());
try {
FileUtil.uploadFile(file.getBytes(), templateConfig.getProfile() + "/CourseUpload/"+ new SimpleDateFormat("yyyy/MM/dd/").format(date), fileName);
} catch (Exception e) {
return "上传失败";
}
return sysFile.getUrl();
}
添加就结束了
下一个编辑
复制添加的哈哈哈
<video style="height:350px;width: 470px;margin-left: 190px" name="courseDemoUrl" id="courseDemoUrl" th:src="*{courseUrl}" th:value="*{courseUrl}" controls="controls" muted autoplay></video>
<input class="form-control"type="file" style="height:auto;margin-left: 188px" id="file" onchange="uploadpic()"/>
所以有的东西会了都那么简单 哎 可惜写的时候不会
加油啦