agea / CmisJS

A CMIS javascript library for node and browser
MIT License
38 stars 34 forks source link

Writing content to file #53

Open cgatian opened 5 years ago

cgatian commented 5 years ago

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 commented 5 years ago

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);
    });
eduardoeriquelme commented 5 years ago

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!