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

您的位置:首頁技術文章
文章詳情頁

node+vue實現文件上傳功能

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

本文實例為大家分享了node+vue實現文件上傳的具體代碼,供大家參考,具體內容如下

*后端*

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’);//設置 視頻文件存放位置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:’服務器繁忙!’ }) }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:’服務器繁忙!’ }) }});

*前端*

<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處理邏輯數據*

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 精品丝袜国产自在线拍亚洲 | 欧美黑寡妇特a级做爰 | 日本久草视频 | 亚洲视频一区在线观看 | 色视频一区二区三区 | 亚洲精品日韩中文字幕久久久 | 她也啪在线视频精品网站 | 久久国产精品免费 | 国产成人深夜福利在线观看 | 色视频www在线播放国产人成 | a黄视频 | 国产午夜免费视频片夜色 | 欧美a级在线 | 中文字幕乱码无线码在线 | 毛片视频网址 | 免费人成在线观看视频不卡 | 久久精品视频播放 | 亚洲在线第一页 | 呦女精品视频 | 在线观看免费a∨网站 | 欧美成人在线观看 | 在线欧美色 | 亚洲第一区精品日韩在线播放 | 久在草在线 | 国产精品欧美一区二区三区 | 欧美日韩另类综合 | 精品国产系列 | 亚洲天堂2015 | 国产精选莉莉私人影院 | 亚洲综合久久久久久中文字幕 | 色一欲一性一乱一区二区三区 | 收集最新中文国产中文字幕 | 久久久国产免费影院 | 国产亚洲小视频 | 午夜美女久久久久爽久久 | 成人在线第一页 | 日本精品高清一区二区2021 | 欧美色偷偷 | 一区二区影院 | 性亚洲精品 | 男人又粗又硬桶女人免费 |