資源簡介
關于上傳的代碼都在壓縮包里頭了,copy過去就可以使用,附帶解碼轉碼工具!
代碼片段和文件信息
package?com.mll.mt.upload;
import?com.mll.mt.login.entity.VideoEntity;
import?com.mll.mt.login.service.LoginService;
import?com.mll.mt.utils.uploadutil.ConverVideoTest;
import?org.apache.catalina.servlet4preview.http.HttpServletRequest;
import?org.springframework.beans.factory.annotation.Autowired;
import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.RequestMapping;
import?org.springframework.web.bind.annotation.RequestParam;
import?org.springframework.web.multipart.MultipartFile;
import?java.io.*;
import?java.util.Date;
import?java.util.List;
/**
?*?@Auther:?wll
?*?@Date:?2018/10/25?17:17
?*?@Description:??視頻文件上傳
?*/
@Controller
@RequestMapping(“upload“)
public?class?UploadVideoController?{
????@Autowired?private?LoginService?loginService;
????@RequestMapping(“/uploadVideo“)
????public?String?uploadVideo(@RequestParam(“file“)?MultipartFile?file
????????????????????????????????????HttpServletRequest?req?HttpServletRequest?request)?{
????????System.out.println(“----------“?+?file.getSize());
????????System.out.println(“----------“);
????????System.out.println(“----------“);
????????if?(file.getSize()?!=?0)?{
????????????//上傳的多格式的視頻文件-作為臨時路徑保存,轉碼以后刪除-路徑不能寫
????????????String?path?=?“C:/shipin/“;
????????????File?TempFile?=?new?File(path);
????????????if?(TempFile.exists())?{
????????????????if?(TempFile.isDirectory())?{
????????????????????System.out.println(“該文件夾存在。“);
????????????????}?else?{
????????????????????System.out.println(“同名的文件存在,不能創建文件夾。“);
????????????????}
????????????}?else?{
????????????????System.out.println(“文件夾不存在,創建該文件夾。“);
????????????????TempFile.mkdir();
????????????}
????????????//?獲取上傳時候的文件名
????????????String?filename?=?file.getOriginalFilename();
????????????//?獲取文件后綴名
????????????String?filename_extension?=?filename.substring(filename.lastIndexOf(“.“)?+?1);
????????????System.out.println(“視頻的后綴名:“?+?filename_extension);
????????????//時間戳做新的文件名,避免中文亂碼-重新生成filename
?????????????long?filename1?=?new?Date().getTime();
????????????filename?=?Long.toString(filename1)?+?“.“?+?filename_extension;
????????????//去掉后綴的文件名
????????????String?filename2?=?filename.substring(0?filename.lastIndexOf(“.“));
????????????System.out.println(“視頻名為:“?+?filename2);
????????????//源視頻地址+重命名后的視頻名+視頻后綴
????????????String?yuanPATH?=?(path?+?filename);
????????????System.out.println(“視頻的完整文件名1:“?+?filename);
????????????System.out.println(“源視頻路徑為:“?+?yuanPATH);
????????????//上傳到本地磁盤/服務器
????????????try?{
????????????????System.out.println(“寫入本地磁盤/服務器“);
????????????????InputStream?is?=?file.getInputStream();
????????????????OutputStream?os?=?new?FileOutputStream(new?File(path?filename));
????????????????int?len?=?0;
????????????????byte[]?buffer?=?new?byte[2048];
????????????????while?((len?=?is.read(buffer))?!=?-1)?{
????????????????????os.write(buffer?0?len);
????????????????}
????????????????os.close()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????819??2018-10-30?10:41??視頻上傳功能源碼\源碼\config\UplocadConfig.java
?????文件??????69002??2018-10-25?17:45??視頻上傳功能源碼\源碼\jar\commons-fileupload-1.3.1.jar
?????文件?????208700??2018-09-11?11:29??視頻上傳功能源碼\源碼\jar\commons-io-2.5.jar
?????文件??????93871??2013-09-16?14:51??視頻上傳功能源碼\源碼\js\videojs\jquery.min.js
?????文件??????56851??2018-10-29?15:24??視頻上傳功能源碼\源碼\js\videojs\video-js.min.css
?????文件?????277472??2018-10-29?15:09??視頻上傳功能源碼\源碼\js\videojs\video.min.js
?????文件??????27279??2018-01-05?17:05??視頻上傳功能源碼\源碼\js\videojs\videojs-ie8.min.js
?????文件???????2327??2018-10-29?16:49??視頻上傳功能源碼\源碼\jsp\video.ftl
?????文件???????1033??2018-10-30?10:41??視頻上傳功能源碼\源碼\uploadutil\Contants.java
?????文件???????1415??2018-10-30?10:42??視頻上傳功能源碼\源碼\uploadutil\ConverVideoTest.java
?????文件??????21429??2018-10-26?10:22??視頻上傳功能源碼\源碼\uploadutil\ConverVideoUtils.java
?????文件???????8014??2018-10-30?10:43??視頻上傳功能源碼\源碼\UploadVideoController.java
?????文件???62871552??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\bin\ffmpeg.exe
?????文件???62753280??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\bin\ffplay.exe
?????文件???62777344??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\bin\ffprobe.exe
?????文件?????109519??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\bootstrap.min.css
?????文件???????2494??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\default.css
?????文件??????43101??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\developer.html
?????文件??????53081??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\faq.html
?????文件??????13383??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\fate.html
?????文件????1585963??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-all.html
?????文件??????29420??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-bitstream-filters.html
?????文件?????196236??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-codecs.html
?????文件??????95800??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-devices.html
?????文件?????865387??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-filters.html
?????文件?????167505??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-formats.html
?????文件??????69930??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-protocols.html
?????文件??????13536??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-resampler.html
?????文件???????7414??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-scaler.html
?????文件??????44113??2018-06-19?03:16??視頻上傳功能源碼\轉碼解碼工具\ffmpeg\doc\ffmpeg-utils.html
............此處省略47個文件信息
評論
共有 條評論