CmisJS icon indicating copy to clipboard operation
CmisJS copied to clipboard

Writing content to file

Open cgatian opened this issue 6 years ago • 2 comments

I've been able to get the content by calling

session.getContentStream(objectId).then(res => {
   console.log(res.text());
});

But this returns images as encoded text. How can I read the response stream to a file buffer?

cgatian avatar Jul 24 '18 19:07 cgatian

Finally have it writing the content. I had to cast the response.body to a PassThrough and then pipe that to a writable stream. Im pretty new to NodeJs development so any pointers would be much appreciated.

session.setCredentials("admin", "admin").loadRepositories()
    .then(() => session.query(`
        SELECT *
        FROM cmis:document WHERE cmis:name LIKE '%test%'`)
    )
    .then(data => {
        return data.results[0].succinctProperties["cmis:objectId"];
    })
    .then(objectId => {
        return session.getContentStream(objectId);
    })
    .then(res => {
        return (res.body as any) as PassThrough;
    }).then(text => {
        var writeStream = fs.createWriteStream("file1.png", {encoding:"binary"});
        text.pipe(writeStream);
    });

cgatian avatar Jul 24 '18 19:07 cgatian

Hello @cgatian ... I'm also new to Node JS and CMIS so I would like to ask a very basic question. How do you get to run this CmisJS project locally? - I would appreciate any help... Thanks!

eduardoeriquelme avatar Jul 31 '18 19:07 eduardoeriquelme