gitana / gitana-javascript-driver

Cloud CMS JavaScript Driver Library
https://www.cloudcms.com
Apache License 2.0
11 stars 10 forks source link

Issue on download method #10

Closed tenoriojuann closed 6 years ago

tenoriojuann commented 6 years ago

I end up with a corrupted image when looping through a node's attachments and downloading the attachment.

I am probably making some silly mistake but I saw no other information for this method other than it downloads the image.

//const path = ...
//const node = ...
//const fs = ...
node.listAttachments().each(function () {
           const attachment = this;
           if (attachment.getId() === 'default') {
                attachment.download(function (binaryData) {
                      fs.writeFile(path, binaryData, 'binary', function (err) {
                           if(err){
                              // do something else
                           }
                     });
                     if (!binaryData) {
                        // do something else
                     }
              })
           }
})
mibewh commented 6 years ago

I didn't see anything wrong with your code at first glance. Please send this to support@cloudcms.com so that it can go through the right channels.

tenoriojuann commented 6 years ago

This was fixed in a newer commit.