Servir des binaires (PDF/PPT/GIF...)

cancel
Showing results for 
Search instead for 
Did you mean: 
flefoll
Member II

Servir des binaires (PDF/PPT/GIF...)

Bonjour,

(je poste le même message sur le forum anglophone - je copierais les réponses pour que quelque soit la langue tout le monde puisse retomber sur les réponses)

Le script suivant fonctionne parfaitement pour fournir du contenu XML mais pas des binaires :

view.get.desc.xml

<webscript>
        <shortname>View</shortname>
        <description>View file</description>
        <url>/view/{path}</url>
        <authentication runas="admin">none</authentication>
        <transaction>required</transaction>
</webscript>

view.get.js

// locate folder by path
// NOTE: only supports path beneath company home, not from root
logger.log("Start View script. Requested resource : " + url.extension);
var alfrescoCompanyHomeFolder = "Company Home";
logger.log("Alfresco company folder name : " + alfrescoCompanyHomeFolder);
var baseFolderPath = "My_Folder";
logger.log("Base folder path : " + baseFolderPath);
var completePath = (alfrescoCompanyHomeFolder + "/" + baseFolderPath + "/" + url.extension).replace(new RegExp("_SPACE_","g"), " ")
;
logger.log("Real requested path : " + completePath);
var requestFile = roothome.childByNamePath(completePath);
if (requestFile == undefined) {
        logger.log("Requested resource is not found");
    status.code = 404;
    status.message = "Requested resource is not found";
    status.redirect = true;
} else if (requestFile.isContainer) {
        logger.log("Browsing is not allowed");
    status.code = 403;
    status.message = "Browsing is not allowed";
    status.redirect = true;
} else {
        logger.log("Rendering selected file");
        model.requestFile = requestFile;
}

view.get.xml.ftl

${requestFile.content}

Que dois-je mettre dans view.get.pdf.ftl  ou dans view.get.ppt.ftl  pour que cela fonctionne sur le même principe ?

PS: les MimeType PDF/PPT sont déjà déclarés au niveau webscript-framework-application-context.

Merci beaucoup,

Francois.
1 Reply
flefoll
Member II

Re: Servir des binaires (PDF/PPT/GIF...)

J'ai trouvé moi-même la réponse après deux bonnes journées….

Ca servira peut-être à d'autres.

Après avoir fait la modif indiquée ici : https://issues.alfresco.com/jira/browse/ETHREEOH-1630

view.get.desc.xml
<webscript kind="org.alfresco.repository.content.stream">
        <shortname>Webview rendering</shortname>
        <description>Render selected file
        </description>
        <url>/view/{path}</url>
        <format default="">argument</format>
        <authentication runas="admin">none</authentication>
        <transaction>required</transaction>
</webscript>

webview.get.js

// locate folder by path
// NOTE: only supports path beneath company home, not from root
logger.log("Start webview script. Requested resource : " + url.extension);
var alfrescoCompanyHomeFolder = "Company Home";
logger.log("Alfresco company folder name : " + alfrescoCompanyHomeFolder);
var baseFolderPath = "My_Folder";
logger.log("Base folder path : " + baseFolderPath);
var completePath = (alfrescoCompanyHomeFolder + "/" + baseFolderPath + "/" + url.extension).replace(new RegExp("_SPACE_","g")
, " ");
logger.log("Real requested path : " + completePath);
var requestFile = roothome.childByNamePath(completePath);
if (requestFile == undefined) {
        logger.log("Requested resource is not found");
    status.code = 404;
    status.message = "Requested resource is not found";
    status.redirect = true;
} else if (requestFile.isContainer) {
        logger.log("Browsing is not allowed");
    status.code = 403;
    status.message = "Browsing is not allowed";
    status.redirect = true;
} else {
        logger.log("Rendering selected file");
        model.contentNode = requestFile;
}

A+