cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Web Script for document Download

cris_cc
Champ in-the-making
Champ in-the-making
Hello everyone,
I need to write a custom Web Script in order to download a file from the repository.
I know that there are native services to do that, but I need to validate the document id through other back-end systems using remote.call

Here what I've done so far in the cstdownload.get.js :

var nodeid = args.nodeid;

if ( crossCheck(nodeid) ){ // This is a Custom function!!!
   
    var file = search.findNode("workspace://SpacesStore/" + nodeid);

   // Render the content of the file here !!! HELP pls!!
  
}else{
    status.code = 400;
    status.message = "Check on back-end system is failed!";
    status.redirect = true;
}

function crossCheck(nodeid){
…..
}

Does anyone have some suggestion where I can find some good example to do that?

I checked the forum and alfresco docs, but I've just found example about native services.

I'm running Alfresco Community v3.2.0 (r2 2440).

Thanks in advance,
Cris
3 REPLIES 3

amarendra_thaku
Champ in-the-making
Champ in-the-making
Dear Cris,

You can use

var fileDownLoadUrl = file[0].downloadUrl;

If this does`nt work then in the ftl you can use

${file[0].downloadUrl}

Thanks & Regards

Amarendra Thakur

cris_cc
Champ in-the-making
Champ in-the-making
Hi Amarendra,
thanks for your reply.

But the solution you sent is not helping me.

Basically the following code:
var fileDownLoadUrl = file.downloadUrl;
just produce the service path to use to download the file (something like "/d/a/workspace/SpacesStore/eb0d2fa7-ff5f-440c-9f49-6edc4036b6ce/mypic.jpg"), and it could be used in the xml/html output (ie: cstdownload.get.xml.ftl) as link to the file download.

What I'm looking for is how to stream the file directly from the Web Script.

Thanks,
Cris

jottley
Confirmed Champ
Confirmed Champ
Take a look at enabling the remote object http://drquyong.com/myblog/?p=49 in the core repository.

Usage information is here: http://wiki.alfresco.com/wiki/Surf_Platform_-_Freemarker_Template_and_JavaScript_API#remote