Modifications pour le document Download Attachments
Modifié par Paul Libbrecht (admin) le 2021/12/12 21:39
<
>
modifié par Paul Libbrecht (admin)
sur 2016/08/18 23:58
sur 2016/08/18 23:58
modifié par Paul Libbrecht (admin)
sur 2016/08/19 20:13
sur 2016/08/19 20:13
Commentaire de modification :
Il n'y a aucun commentaire pour cette version
Résumé
Détails
- Propriétés de la Page
-
- Contenu
-
... ... @@ -15,8 +15,11 @@ 15 15 16 16 if(page && pageDoc) { 17 17 System.err.println("Should download attachments from page ${pageDoc}."); 18 + def uncompressedMimes = ["image/jpeg", "image/png", "application/zip"]; 18 18 response.setContentType("application/zip"); 19 - response.addHeader("Content-Disposition", "attachment; filename=${pageDoc.getName()}_attachments.zip"); 20 + String name = pageDoc.getName(); 21 + if(name=="WebHome") name = pageDoc.getSpace(); 22 + response.addHeader("Content-Disposition", "attachment; filename=${name}_attachments.zip"); 20 20 21 21 22 22 ZipOutputStream out = null; ... ... @@ -26,8 +26,14 @@ 26 26 for(Attachment att in pageDoc.getAttachmentList()) { 27 27 System.err.println("Outputting " + att.filename); 28 28 ZipEntry entry = new ZipEntry(att.filename); 32 + entry.setTime(att.getDate().getTime()); 33 + entry.setSize(att.filesize); 34 + if(uncompressedMimes.contain(att.mimeType)) 35 + entry.setMethod(ZipEntry.STORED); 36 + else 37 + entry.setMethod(ZipEntry.DEFLATED); 29 29 out.putNextEntry(entry); 30 - IOUtils.copy(att.contentInputStream, out); 39 + IOUtils.copy(att.contentInputStream, out, 5*1024*1024); 31 31 } 32 32 } catch (Exception ex) { 33 33 ex.printStackTrace(); ... ... @@ -38,7 +38,10 @@ 38 38 } 39 39 40 40 } else { 41 - println("Sorry, I need a page parameter."); 50 + println(""" 51 += Download Attachments Macro = 52 +Use as ~{~{downloadAttachments/~}~} so see a list of attachments. 53 +"""); 42 42 } 43 43 44 44