In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to upload files and generate thumbnails in Java. It is very detailed and has a certain reference value. Friends who are interested must read it!
One: demand
One of the needs of users is the collection function, simple collection records are easy to do, but want to add some difficulty is to generate thumbnails. Similar to bilibili's collection.
Second: how to achieve the requirements and the problems encountered in it? Problems encountered in requirements analysis
1. How do I generate thumbnails?
two。 Generate thumbnails when collecting or thumbnails when uploading files?
3. Where are the generated thumbnails stored?
Problems encountered in the coding process
1. File interception is relatively slow, how to solve it?
Method: use multithreading
two。 Can't get the network file through new File ()?
File file = new File ("http://d-godone.dmsd.tech/goDone/M00/00/0A/wKg8O2D2mnqEMg7wAAAAALbl5Ys275.pdf");
Method: use the tool class FileUtils.copyURLToFile (url,file)
3. MultipartFile type is required for file upload, but the intercepted types are Frame and BufferedImage. How to do it?
Methods: the method of consulting data to encapsulate and converting files.
Three: flow chart and UML diagram
Four: upload files to generate thumbnails 1. Upload pictures to generate thumbnails-- FastDFS/** * @ Author: Promsing (Zhang Youbo) * @ Date: 2021-9-18-0:25 * @ Description: image processing class * @ version: 1.0 * / @ Slf4j@Componentpublic class ImageProcessing extends TypeProcessing {@ Autowired private FastFileStorageClient fastFileStorageClient; @ Autowired private ThumbImageConfig thumbImageConfig; private String group= "http://192.168.y.y:8888/group1/"; / * * @ param fileName location of local files * @ return * / @ Override public String fileUpload (String fileName) {File file = new File (fileName); / / upload and generate thumbnails StorePath storePath = null Try {storePath = this.fastFileStorageClient.uploadImageAndCrtThumbImage (new FileInputStream (file), file.length (), "png", null);} catch (FileNotFoundException e) {e.printStackTrace ();} / / String path = thumbImageConfig.getThumbImagePath (storePath.getPath ()); String imageUrl=group+thumbImageConfig.getThumbImagePath (storePath.getPath ()); return imageUrl;} 2. Upload videos to generate thumbnails-- javacv/** * @ Author: Promsing (Zhang Youbo) * @ Date: 2021-9-18-0:37 * @ Description: video processing class * @ version: 1.0 * / @ Component@Slf4jpublic class VideoProcessing extends TypeProcessing {@ Override public String fileUpload (String videoFileName) {/ / path of the image of the last obtained video String videPicture= "" / / Frame object Frame frame = null; / / identity int flag = 0; try {/ * get video file * / FFmpegFrameGrabber fFmpegFrameGrabber = new FFmpegFrameGrabber (videoPath + "/" + videoFileName); FFmpegFrameGrabber fFmpegFrameGrabber = new FFmpegFrameGrabber (videoFileName); fFmpegFrameGrabber.start () / / get the total number of video frames int ftp = fFmpegFrameGrabber.getLengthInFrames (); log.info ("duration" + ftp / fFmpegFrameGrabber.getFrameRate () / 60); while (flag)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.