This article mainly introduces the implementation of the attachment preview function in JavaScript. The specific operation steps can be found in detail below. Interested friends can refer to it.
Since the company's EMP imaging platform is relatively cumbersome and needs to be downloaded before it can be previewed, the business staff proposed to add a preview page to the attachment list page. Today I will record the completed process:
One is the js version, the other is the jquery version, the js version is used here. The jquery version is just introduced slightly differently.
1. Introduce the plug-in (uploaded)
##2. Bring the preview page to life
##
<SCRIPT> var attach_path= '${param.attach_path}'; var attach_name= decodeURI('${param.attach_name}'); var attachPath= new Array(); attachName=attach_name.split(","); var attachPath1= new Array(); attachPath1=attach_path.split(","); for (var i=0;i<attachPath1.length;i++) { attachPath2='102storage'+attachPath1[i]; $("#jq22").append("<li><img alt='"+attachName[i]+"' src='"+attachPath2+"'></li>"); } $(function() { $('#jq22').viewer({ url: 'src', }); }); </SCRIPT>
import java.io.*; import java.util.ArrayList;import java.util.Enumeration;
import java.util.List ;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import com.yucheng.cmis.operation.CMISOperation;
import com.github .junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
Considering that decompression will occupy the space of the shared disk, asynchronous deletion is performed after decompression. The time is 20s, which is enough time. However, if you click to reload the page after 20s, the image will fail to load because the image is The path has expired.
//异步删除文件(节省空间) List<Thread> threadList = new ArrayList<Thread>(); Thread thread = new Thread(new DeleteTemporaryFolder(dstDirectoryPath)); thread.start(); for(Thread t : threadList){ try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } }
When displaying pictures, the page cannot access the project As the image path, you need to execute the mount command to mount the shared disk path to a path under the project
mount --bind /testshare01 /app/cmis/project/cmis.war/ff/ testshare01This way it can be displayed normallyThe above is the detailed content of Introduction to the code for previewing attachments in JavaScript. For more information, please follow other related articles on the PHP Chinese website!