Writing content to file
Opened this issue · 2 comments
cgatian commented
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
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
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!