亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

node+vue實(shí)現(xiàn)文件上傳功能

瀏覽:108日期:2023-01-17 18:09:07

本文實(shí)例為大家分享了node+vue實(shí)現(xiàn)文件上傳的具體代碼,供大家參考,具體內(nèi)容如下

*后端*

const express = require(’express’);const Router = express.Router();const multer = require(’multer’);const fs = require(’fs’);const pathLib = require(’path’);const videoModel = require(’../../models/my_yx_app/video’);//設(shè)置 視頻文件存放位置const uploadVido = multer({ dest:’uploads_yx_app/video/’});//上傳視頻Router.post(’/uploadVideo’,uploadVido.single(’file’),(req,res)=>{ if (req.file) { let file = req.file; let newName = file.path+pathLib.parse(file.originalname).ext; //修改path fs.rename(file.path,newName,(err)=>{ //修改path if (err) { return res.status(200).json({ code:0, msg:’服務(wù)器繁忙!’ }) }else { return res.status(200).json({ code:1, msg:’上傳完成’, title:pathLib.parse(file.originalname).name, videoUrl:’http://127.0.0.1:3001/uploads_yx_app/video/’+file.filename+pathLib.parse(file.originalname).ext }) } }) }else { return res.status(200).json({ code:0, msg:’服務(wù)器繁忙!’ }) }});

*前端*

<div style='position: relative'> <!--此處name 與 uploadVido.single(’file’) 相同--> <input type='file' name='file' @change='changeFile' class='customStyle'> <el-button size='mini' type='primary'> 添加文件 <i class='el-icon-upload el-icon--right'></i> </el-button> <div class='zt-title-video'>{{ file.name }}</div> <div v-show='percentageShow'> <el-progress :text-inside='true' :stroke- :percentage='percentage' > </el-progress> </div></div>

*js處理邏輯數(shù)據(jù)*

saveData() { //上傳 let that = this; let fd = new FormData(); fd.append(’file’, this.file); fileUpdata({ //上傳文件存儲(chǔ)在后端 method: ’post’, url: ’/uploadVideo’, data: fd, //監(jiān)聽上傳時(shí)間 //實(shí)現(xiàn)進(jìn)度條 onUploadProgress(progressEvent) { that.percentageShow = true; that.percentage = parseInt(((progressEvent.loaded / progressEvent.total) * 100)); } }).then(res => { if (res.data.code === 1) { //數(shù)據(jù)持久化 fileUpdata({ method: ’post’, url: ’/saveVideoInfo’, data: { videoUrl: res.data.videoUrl, //路徑 videoName: res.data.title, //標(biāo)題 videoType:that.videoType, //類型 userName:localStorage.getItem(’username’) //那個(gè)用戶上傳的 } }).then(res => { if (res.data.code === 1) { setTimeout(function () { //為什么延遲,為了使進(jìn)度條走完 that.$message({ message: ’上傳成功’, type: ’success’ }) }, 1000); } }).catch(err => { this.$message.error(’服務(wù)器繁忙,請(qǐng)稍后重試!’); }); } }).catch(err => { this.$message.error(’服務(wù)器繁忙,請(qǐng)稍后重試!’); }) },

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 欧美色爱综合 | 一级大黄美女免费播放 | 国产精品永久在线 | 国产大量女主播精品视频 | 热久久影院 | 欧美黄色三级 | 黄色片网站在线 | 色中文字幕 | 免费爱爱 | 国产高清一区二区三区四区 | 免费国产一级特黄aa大 | 999www人成免费视频 | 可以免费看的黄色网址 | 国产a一级毛片午夜剧院 | 小蝌蚪在线成人免费视频 | 一级黄色大片免费观看 | 国产福利写真视频在线观看 | 三级a毛片 | 国产综合色在线视频区 | 黄色片大全在线观看 | 草草草视频在线观看 | 一区二区视频在线免费观看 | 青青草视频在线观看免费 | 永久免费视频 | 在线看黄色网址 | 国产亚洲第一伦理第一区 | 亚州免费一级毛片 | 亚洲依依成人精品 | 亚洲综合极品香蕉久久网 | 全免费午夜真人毛片视频 | 三级黄色毛片 | 国产精品宅男在线观看 | 久久综合给合久久狠狠狠色97 | 亚洲第5页 | 国产三级大片 | 国产视频视频 | 日韩一级片视频 | 免费在线黄色网址 | 一级毛片免费全部播放完整 | 很黄很黄视频 | 一区二区三区四区在线不卡高清 |