<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Springboot+vue實(shí)現(xiàn)上傳視頻并在線播放功能

          共 5708字,需瀏覽 12分鐘

           ·

          2020-08-28 01:22

          點(diǎn)擊上方?web項(xiàng)目開(kāi)發(fā)選擇?設(shè)為星標(biāo)

          優(yōu)質(zhì)文章,及時(shí)送達(dá)





          效果圖

          前端上傳視屏頁(yè)面


          前端上傳視屏成功頁(yè)面






          環(huán)境介紹

          JDK:1.8

          數(shù)據(jù)庫(kù):Mysql5.6

          前端:Vue

          后端:SpringBoot





          完整源碼獲取



          掃碼關(guān)注回復(fù)【視頻上傳】獲取源碼


          如果你在運(yùn)行這個(gè)代碼的過(guò)程中有遇到問(wèn)題,請(qǐng)加小編微信xxf960513,我拉你進(jìn)對(duì)應(yīng)微信學(xué)習(xí)群??!幫助你快速掌握這個(gè)功能代碼!





          核心代碼介紹

          UploadController.class
          package?com.songguoliang.springboot.controller;import com.songguoliang.springboot.domain.ResponseBean;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.*;import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest;import java.io.File;import java.io.IOException;/** * 上傳文件 */@CrossOrigin(origins = "*",maxAge = 3600)@Controllerpublic class UploadController {    private static final Logger LOGGER = LoggerFactory.getLogger(UploadController.class);    @GetMapping("/upload")    public String upload() {        return "upload";    }    @PostMapping("/upload")    @ResponseBody    public ResponseBean upload(@RequestParam("file") MultipartFile file,HttpServletRequest request) {        String filePath = request.getSession().getServletContext().getRealPath("/uploadFile/");        File dir = new File(filePath);        if (!dir.isDirectory()) {//文件目錄不存在,就創(chuàng)建一個(gè)            dir.mkdirs();        }        if (file.isEmpty()) {            return ResponseBean.error("上傳失敗,請(qǐng)選擇文件",null);        }        String fileName = file.getOriginalFilename();        String ext = fileName.substring(fileName.lastIndexOf("."));        String newFileName = System.currentTimeMillis() + ext;        File dest = new File(filePath + File.separator + newFileName);        try {            file.transferTo(dest);            LOGGER.info("上傳成功");            String url =  request.getScheme() +"://" + request.getServerName()                    + ":" +request.getServerPort() + "/uploadFile/";            return ResponseBean.success("上傳成功", url  + newFileName);        } catch (IOException e) {            LOGGER.error(e.toString(), e);        }        return ResponseBean.error("上傳失敗",null);    }}

          application.properties

          ?#?上傳文件總的最大值spring.servlet.multipart.max-request-size=30MB# 單個(gè)文件的最大值spring.servlet.multipart.max-file-size=100MB## jspspring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jsp

          ?index.vue

          <template>  <div class>    <h3>上傳視頻h3>    <el-upload      class="avatar-uploader el-upload--text"      :action="uploadUrl"      :show-file-list="false"      accept=".mp4"      :on-success="handleVideoSuccess"      :before-upload="beforeUploadVideo"      :on-progress="uploadVideoProcess"    >      <video        v-if="showVideoPath != '' && !videoFlag"        :src="showVideoPath"        poster="https://p3-dy.byteimg.com/img/tos-cn-p-0015/6b0ac3f1d60c4a318b69d00f4cc125ff~c5_300x400.jpeg?from=2563711402_large"        type="video/mp4"        class="avatar video-avatar"        controls="controls"        preload="auto"      >        您的瀏覽器不支持視頻播放      video>            <el-progress        v-if="videoFlag == true"        type="circle"        :percentage="videoUploadPercent"        style="margin-top:30px;"      >el-progress>      <el-button        type="primary"        class="video-btn"        slot="trigger"        size="small"        v-if="isShowUploadVideo"      >        選取文件<i class="el-icon-upload el-icon--right">i      >el-button>    el-upload>    <P v-if="isShowUploadVideo" class="text"      >請(qǐng)保證視頻格式是.mp4,且不超過(guò)20MP    >  div>template>
          <script>import axios from "axios";export default { props: {}, data() { return { form: {}, uploadUrl: "http://localhost:8080/upload", //你要上傳視頻到你后臺(tái)的地址 videoShow:true, videoFlag: false, //是否顯示進(jìn)度條 videoUploadPercent: "", //進(jìn)度條的進(jìn)度, isShowUploadVideo: true, //顯示上傳按鈕 showVideoPath: "" // 視頻地址 // showVideoPath: "https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200fed0000bsgf4g46hqrc1h8adp50&ratio=720p&line=0" // 視頻地址 }; }, mounted() {}, methods: { //上傳前回調(diào) beforeUploadVideo(file) { const isLt20M = file.size / 1024 / 1024 < 20; if (["video/mp4"].indexOf(file.type) == -1) { //'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb' this.$message.error("請(qǐng)保證視頻格式是.mp4哦!"); return false; } if (!isLt20M) { this.$message.error("上傳視頻大小不能超過(guò)20MB哦!"); return false; } this.isShowUploadVideo = false; },
          //進(jìn)度條 uploadVideoProcess(event, file, fileList) { this.videoFlag = true; this.videoUploadPercent = file.percentage.toFixed(0) * 1; },
          //上傳成功回調(diào) handleVideoSuccess(res, file) { this.isShowUploadVideo = true; this.videoFlag = false; this.videoUploadPercent = 0; if (res.errorCode == "0") { this.showVideoPath = res.data; } else { this.$message.error("視頻上傳失敗,請(qǐng)重新上傳!"); } } }};script>
          <style scoped lang="scss">.avatar { width: 300px; height: 300px;}style>

          main.js

          import Vue from 'vue'
          import 'normalize.css/normalize.css' // A modern alternative to CSS resets
          import ElementUI from 'element-ui'import 'element-ui/lib/theme-chalk/index.css'import locale from 'element-ui/lib/locale/lang/en' // lang i18n
          import '@/styles/index.scss' // global css
          import App from './App'import store from './store'import router from './router'
          import '@/icons' // iconimport '@/permission' // permission control
          /** * If you don't want to use mock-server * you want to use MockJs for mock api * you can execute: mockXHR() * * Currently MockJs will be used in the production environment, * please remove it before going online ! ! ! */if (process.env.NODE_ENV === 'production') { const { mockXHR } = require('../mock') mockXHR()}
          // set ElementUI lang to ENVue.use(ElementUI, { locale })// 如果想要中文版 element-ui,按如下方式聲明// Vue.use(ElementUI)
          Vue.config.productionTip = false
          new Vue({ el: '#app', router, store, render: h => h(App)})

          --完--


          如果你覺(jué)得這個(gè)案例以及我們的分享思路不錯(cuò),對(duì)你有幫助,請(qǐng)分享給身邊更多需要學(xué)習(xí)的朋友。別忘了《留言+點(diǎn)在看》給作者一個(gè)鼓勵(lì)哦!


          推薦案例

          1、springboot+mybatis+vue前后端分離實(shí)現(xiàn)用戶(hù)登陸注冊(cè)功能

          2、SpringBoot+Vue前后分離實(shí)現(xiàn)郵件發(fā)送功能

          3、SpringBoot+Spring Data JPA+Vue前后端分離實(shí)現(xiàn)分頁(yè)功能

          4、SpringBoot+Spring Data JPA+Vue前后端分離實(shí)現(xiàn)Excel導(dǎo)出功能

          5、Spring Boot + Vue前后端分離實(shí)現(xiàn)圖片上傳功能

          6、springboot+jpa+tymeleaf實(shí)現(xiàn)分頁(yè)功能

          7、springboot+jpa+thymeleaf實(shí)現(xiàn)信息修改功能

          8、SpringBoot+vue開(kāi)發(fā)微信小程序留言功能

          9、SpringBoot實(shí)現(xiàn)生成帶參數(shù)的小程序二維碼功能

          10、springboot+jpa+thymeleaf實(shí)現(xiàn)信息增刪改查功能

          11、用java實(shí)現(xiàn)Graphics2D繪制驗(yàn)證碼功能

          12、Springboot+layui前后端分離實(shí)現(xiàn)word轉(zhuǎn)pdf功能

          13、用java將本地圖片轉(zhuǎn)base64格式, 再轉(zhuǎn)圖片!你用過(guò)這個(gè)功能?

          14、springboot+layui+thymelefe實(shí)現(xiàn)用戶(hù)批量添加功能

          15、springboot+Tymeleaf實(shí)現(xiàn)用戶(hù)密碼MD5加鹽解密登錄

          16、springboot+vue實(shí)現(xiàn)用戶(hù)注冊(cè)后必須通過(guò)郵箱激活才能登錄激活才能登錄

          17、SpringBoot+Vue實(shí)現(xiàn)用戶(hù)頭像修改功能

          18、Springboot+Vue實(shí)現(xiàn)富文本發(fā)表文章功能

          19、springboot+vue實(shí)現(xiàn)不同管理權(quán)限的用戶(hù)登陸展示的菜單欄目不同功能

          溫暖提示

          為了方便大家更好的學(xué)習(xí),本公眾號(hào)經(jīng)常分享一些完整的單個(gè)功能案例代碼給大家去練習(xí),如果本公眾號(hào)沒(méi)有你要學(xué)習(xí)的功能案例,你可以聯(lián)系小編(微信:xxf960513)提供你的小需求給我,我安排我們這邊的開(kāi)發(fā)團(tuán)隊(duì)免費(fèi)幫你完成你的案例。
          注意:只能提單個(gè)功能的需求不能要求功能太多,比如要求用什么技術(shù),有幾個(gè)頁(yè)面,頁(yè)面要求怎么樣?


          瀏覽 286
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  2020伊人网 | 热久久思思热 | 免费操屄网 | 8x8x皇冠视频免费观看 | 日日夜夜免费看三级片 |