brenden / node-webshot

Easy website screenshots in Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image not being generated on server but same code generates image locally

harsh-rayzada opened this issue · comments

Hi there.

I am using webshot on my node(sails js) project to convert an html string to an image and then upload that image to a s3 bucket. When I run it on my local machine, it works fine i.e it generates an image and I am able to upload that image to s3 bucket. But when I run the same code on a EC2 instance(ubuntu v16), it just doesnt work. It just doesnt create any image and hence nothing gets uploaded.

Here is my code -

var htmlString = '<div>a long html string</div>';
webshot(htmlString,'img.png', options, function(err) {
   fs.readFile('img.png', function (err, data){
     if(err){
        console.log('error reading file');
     }else{
        var params = {
                Bucket: bucket,
                Key: 'customPNGs/'+'img.png',
                Body: data,
                ACL: 'public-read',
                ContentType: 'image/png'
        };
        s3.putObject(params, function (err, res) {
             if (err) {
              sails.log.error("Error uploading data: ", err);
         } else {
              console.log('uploaded')                  
         }
    });
     }
});

I tried doing the uploading directly to s3 using streams but it uploads a 0kb file.
Here is my code using the stream

var renderStream = webshot(quitImageHTML, null, options);
var ss = '';
renderStream.on('data', function(data) {
     ss+=data.toString('binary');
});
renderStream.on('end', function() {
    //upload using the above code
});

Please help. Its urgent for me to get it working for my project asap. Thankz in advance.

commented

On the server try
sudo apt-get install libfontconfig
should help
glhf

Works like a charm...Thankz a ton