On the server I would like to take a screenshot of an external link and save it to the server in a folder.
I am trying to use the package webshot for meteor:
https://github.com/TimHeckel/meteor-webshot
But it is not working. I installed the package using mrt add webshot. The package installed successfully. According to this stackoverflow: How to use webshot with meteor
I was able to edit the package.js file for webshot to export WEBSHOT variable server side like so:
Package.on_use(function (api) {
api.add_files("lib/webshot.js", "server");
api.export("WEBSHOT","server"); // This was the new line added to export WEBSHOT
});
This is the code I am calling server side to take the webshot:
Meteor.methods
post: (postAttributes) ->
console.log postAttributes.url // 'http://yahoo.com'
_image = "myscreenshot.png";
_res = WEBSHOT.snap(postAttributes.url, "public/exports~/" + _image,
screenSize:
width: 300
height: 300
)
I have a directory in the public folder called exports~ and when I run my code no image is saved to the directory, and I do not get any errors. I have no clue what is happening!
Since I have setup my meteor to be able to install npm packages server side, I also tried to use the npm webshot package by installing using the regular old npm install webshot.
Then I tried using webshot = Meteor.require('webshot') but it never worked because I could not start the app as it kept crashing with error like:
node_modules/webshot/node_modules/phantomjs/node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template........
So I cannot use webshot the regular npm using Meteor.require. But I finally got it working when using the meteor smart package as long as I add
api.export("WEBSHOT","server");
to the package.js file for webshot. But still it does not actually take the screenshot. Please someone clue me in!