<div data-dojo-attach-point="imageViewPane" data-dojo-type="dijit.layout.ContentPane" style="overflow-x: hidden;overflow-y: hidden;display:none">
<image src="" data-dojo-attach-point="viewImage" style="height: 380px; height: expression(this.width > 380 ? 380:true);max-width:800px; width: expression(this.width > 800 ? 800: true);" >
</div>
/**
* 下载主附件-(用于在线预览)
*
* @param osName
* @param docId
* @param response
* @param request
* @throws EcmException
*/
public static void downloadPrimaryAttach(String osName, String docId, HttpServletResponse response, HttpServletRequest request) throws EcmException {
EntityManager em = null;
OutputStream out = null;
try {
out = response.getOutputStream();
em = DaoManager.getEntityManager();
ObjectStore os = ObjectStoreHelper.getObjectStore(osName);
Document doc = P8DocumentDao.fetchDocumentById(os, docId);
Collection<ContentTransfer> collection = EngineCollectionUtils.c(doc.get_ContentElements(), ContentTransfer.class);
if (collection.size() == 0) {// 没有附件
throw new EcmException(ErrorCode.ATTACHMENT_NULL_ERROR, "attach is null error ", new Exception("attach is null error"));
}
Iterator<ContentTransfer> it = collection.iterator();
ContentTransfer content = it.next();
String fileName = AttachmentMapper.getAttachmentNameFromRetrievalName(content.get_RetrievalName());
InputStream in = content.accessContentStream();
String mineType = BatchImportService.getMineType(fileName);
response.setContentType(mineType);
fileName = DownloadUtils.getEncodedFilename(fileName, request);
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
byte[] b = new byte[1024];
int i = -1;
while ((i = in.read(b)) != -1) {
out.write(b);
}
} catch (EcmException e) {
logger.error("downloadAttach error", e);
throw new EcmException(e);
} catch (Exception e) {
logger.error("downloadAttach error", e);
throw new EcmException(ErrorCode.ATTACHMENT_DOWNLOAD_ERROR, "downloadAttach error ", e);
} finally {
if (em != null) {
em.close();
}
if (out != null) {
try {
out.flush();
out.close();
} catch (Exception ex) {
logger.error(ex);
}
}
}
}
![](https://img-my.csdn.net/uploads/201212/29/1356768688_8094.png)
Office 2007 File Format MIME Types for HTTP Content Streaming
Ext | MIME Type |
.doc | application/msword |
.dot | application/msword |
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.dotx | application/vnd.openxmlformats-officedocument.wordprocessingml.template |
.docm | application/vnd.ms-word.document.macroEnabled.12 |
.dotm | application/vnd.ms-word.template.macroEnabled.12 |
.xls | application/vnd.ms-excel |
.xlt | application/vnd.ms-excel |
.xla | application/vnd.ms-excel |
.xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.xltx | application/vnd.openxmlformats-officedocument.spreadsheetml.template |
.xlsm | application/vnd.ms-excel.sheet.macroEnabled.12 |
.xltm | application/vnd.ms-excel.template.macroEnabled.12 |
.xlam | application/vnd.ms-excel.addin.macroEnabled.12 |
.xlsb | application/vnd.ms-excel.sheet.binary.macroEnabled.12 |
.ppt | application/vnd.ms-powerpoint |
.pot | application/vnd.ms-powerpoint |
.pps | application/vnd.ms-powerpoint |
.ppa | application/vnd.ms-powerpoint |
.pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
.potx | application/vnd.openxmlformats-officedocument.presentationml.template |
.ppsx | application/vnd.openxmlformats-officedocument.presentationml.slideshow |
.ppam | application/vnd.ms-powerpoint.addin.macroEnabled.12 |
.pptm | application/vnd.ms-powerpoint.presentation.macroEnabled.12 |
.potm | application/vnd.ms-powerpoint.presentation.macroEnabled.12 |
.ppsm | application/vnd.ms-powerpoint.slideshow.macroEnabled.12 |