In the last article, we used MinIO to implement file storage for a variety of file formats. Sometimes we need not only file storage, but also online preview of files. Here to recommend a file preview artifact based on SpringBoot kkFileView, basic support mainstream file online preview, use is also very simple, I hope to help you!

SpringBoot Actual E-commerce project Mall (50K + STAR)

KkFileView profile

KkFileView can be used to build an online file preview service and is available on Github at 5.7K +Star. The project uses the popular SpringBoot build, easy to start and deploy, basic support mainstream office documents online preview, such as DOCX, XLSX, PPTX, PDF, TXT, ZIP, pictures, video, audio and so on. The project features can be seen in the following figure.

The installation

KkFileView supports installation in Windows and Linux, below we introduce its installation, basically out of the box!

Windows

  • First, download the latest version of the installation package at gitee.com/kekingcn/fi…

  • After the download succeeds, decompress it to the specified directory and run itbinIn the directorystartup.batCommand can;

  • Since this is a SpringBoot project, if you want to change the configuration, you just need to change itconfigIn the directoryapplication.propertiesThe file will do.

Linux

  • Docker installation under Linux is very simple, just two commands, first download the kkFileView Docker image;
docker pull keking/kkfileview
Copy the code
  • After the download is complete run the KKFileView Docker container and the service will run in8012Port;
docker run -p 8012:8012 --name kkfileview \
-d keking/kkfileview
Copy the code
  • After the success of the operation, can visit kkfileview test page, address address: http://192.168.7.109:8012

use

We used MinIO to build the object storage service, and then we combined kkFileView with MinIO. We first stored the files that need to be previewed online in MinIO, and then previewed the files.

  • We can useS3 BrowserTo manage files in MinIO, first create a bucket aspreview, and upload the files;

  • After the upload is successful, modify the access policy of the bucket to allow anonymous users to access the bucket.

  • Reference when modifying a policyPolicy ExamplesCan, pay attention to modifyversionfor2012-10-17;

  • After the modification is successful, you can preview the file online. Let’s look at the URL format of the online preview file. Just pass in the URL (the address of the file that needs to preview)base64Code is ok;
http://192.168.7.109:8012/onlinePreview?url=base64Encode ($url)Copy the code
  • Let’s preview an image and try it out.

  • Then find a website to put the URLbase64To code, I use this:Tool.oschina.net/encrypt?typ…

  • Next, put the URL parameter into the access path to preview the image, is not very simple!

  • If we preview the Word document again, we can see that there is aJPGIn fact, KKFileView is a document preview by converting word documents to PDF or JPG;

  • Then preview the PPT document, PPT document is also converted into PDF and JPG to achieve preview;

  • Let’s preview the PDF file, which is exactly the same as the two above;

  • Then preview the Excel document, this preview effect needs to be improved;

  • Let’s preview the plain text Markdown document;

  • Finally to preview the next compressed file, support to view the content in the compressed file, click the file can be directly preview.

configuration

There are many configurations of KKFileView. For details, refer to the application.properties file in the config directory. Here describes how to customize the configuration in the Docker container.

  • If you want to modify the kkFileView configuration file, you can first copy the configuration file directory from the Docker container.
Docker cp kkfileview: / opt/kkfileview - 3.5.1 track of/config/mydata/kkfileview /Copy the code
  • Then mount the configuration directory, file directory, and log directory to the host and run them.
Docker run - p - 8012-8012 the name kkfileview \ - v/mydata/kkfileview/config: / opt/kkfileview - 3.5.1 track of/config \ - v / mydata/kkFileView/file: / opt/kkFileView - 3.5.1 track of/file \ - v/mydata kkFileView /log: / opt/kkFileView 3.5.1 track of /log \
-d keking/kkfileview
Copy the code
  • If we want to watermark the preview file, we can do soapplication.propertiesFile in the following configuration, such as I want to addmacrozhengThis watermark;
# Watermark content
${WATERMARK_TXT:} = ${WATERMARK_TXT:}
watermark.txt = ${WATERMARK_TXT:macrozheng}
Copy the code
  • After the modification, preview the image again and you will find that the watermark has been added.

conclusion

Through a wave of practice of kkFileView, we found that kkFileView can meet the online preview requirements of Office documents, videos, pictures and other mainstream files, and it is also very simple to use and configure. Because it is through the word, PPT documents into PDF to achieve preview, if you do not have particularly high requirements for Office document preview, you can use it to build a comprehensive online file preview service!

The resources

Official document: kkfileview.keking.cn/zh-cn/index…

In this paper, making github.com/macrozheng/… Welcome to Star!