色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽:120日期: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)稍后重試!’); }) },

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

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 国产精品亚洲专区一区 | 美女被免费网站在线软件 | 美女个护士一级毛片亚洲 | 免费公开视频人人人人人人人 | 中国农村一级毛片 | 九九久久久 | a级国产精品片在线观看 | 国产精品大全 | 国产精品爱久久久久久久小 | a级毛片毛片免费观看久潮喷 | 不卡一区二区在线 | 看日本真人一一级特黄毛片 | 91精品国产91 | 99在线视频精品费观看视 | 深夜做爰性大片很黄很色视频 | 三级在线网站 | 日韩欧美视频一区二区在线观看 | 精品国产亚一区二区三区 | 国产主播大尺度精品福利 | 精品日韩欧美一区二区三区 | 123成人网 | 欧美国产一区二区 | 国产精品一区久久精品 | 亚洲成人播放 | 久久五月女厕所一区二区 | 国产日本三级欧美三级妇三级四 | 一级毛片视频在线 | 亚洲欧美在线视频 | 好叼操这里只有精品 | 亚洲男女视频 | 欧美日韩亚洲成色二本道三区 | 3级黄色| 日韩欧美理论 | 国产区香蕉精品系列在线观看不卡 | 成人免费午夜性视频 | 欧美一级久久久久久久久大 | 国产亚洲精品影达达兔 | 欧美野外性xxxxfeexxxxx | 亚洲偷偷自拍 | 亚洲国产成人在线 | 欧美特黄aaaaaa|