vue elementui上传视屏到服务器并且播放

vue elementui上传视屏到服务器并且播放_第1张图片
前端



模拟上传2



确定上传2

data:
url:‘’
method:
vue elementui上传视屏到服务器并且播放_第2张图片
upload(){
const formData = new FormData()
const reader = new FileReader()
const file = this. r e f s . u p l o a d . u p l o a d F i l e s [ 0 ] c o n s t h e a d e r C o n f i g = h e a d e r s : ′ C o n t e n t − T y p e ′ : ′ m u l t i p a r t / f o r m − d a t a ′ i f ( ! f i l e ) / / 若 未 选 择 文 件 a l e r t ( ′ 请 选 择 文 件 ′ ) r e t u r n f o r m D a t a . a p p e n d ( ′ f i l e ′ , f i l e . r a w ) t h i s . refs.upload.uploadFiles[0] const headerConfig = { headers: { 'Content-Type': 'multipart/form-data' }} if (!file) { // 若未选择文件 alert('请选择文件') return } formData.append('file', file.raw) this. refs.upload.uploadFiles[0]constheaderConfig=headers:ContentType:multipart/formdataif(!file)//alert()returnformData.append(file,file.raw)this.axios.post(’/upload’, formData, headerConfig).then(res => {
// 上传图片
// reader.readAsDataURL(file.raw)
// reader.onload = data => { // 读取完后
// const res = data.target || data.srcElement
// // res.result 为图片的base64格式, 直接放入img标签的src中即可
// this.url= res.path
// console.log(this.url)
// }
// console.log(res.data)
this.url=URL.createObjectURL(file.raw)
this.$refs.video.src=this.url
console.log(this.url)
})
}
后台:
vue elementui上传视屏到服务器并且播放_第3张图片
app.post("/upload",upload.single(‘file’), function(req, res) {
// req.file 是 前端表单name==“imageFile” 的文件信息(不是数组)

res.send(req.file);
})

你可能感兴趣的:(vue.js)