问题描述
在服务器上,我想拍摄一个外部链接的屏幕快照,并将其保存到服务器的文件夹中.
On the server I would like to take a screenshot of an external link and save it to the server in a folder.
我正在尝试使用流星包webshot:
I am trying to use the package webshot for meteor:
https://github.com/TimHeckel/meteor-webshot
但是它不起作用.我使用mrt add webshot安装了软件包.软件包安装成功.根据以下stackoverflow:如何在流星上使用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
我能够编辑webshot的package.js文件,以导出WEBSHOT变量服务器端,如下所示:
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
)
我在公用文件夹中有一个名为exports〜的目录,当我运行代码时,没有图像保存到该目录中,并且没有出现任何错误.我不知道发生了什么事!
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!
由于我已经设置了流星以便能够在服务器端安装npm软件包,所以我还尝试通过使用常规的旧npm install webshot安装来使用npm webshot软件包.
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.
然后,我尝试使用webshot = Meteor.require('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........
所以我不能通过Meteor.require使用webshot常规的npm.但是只要我添加
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");
到用于网络快照的package.js文件.但是,它实际上并没有拍摄屏幕截图.请有人给我提示!
to the package.js file for webshot. But still it does not actually take the screenshot. Please someone clue me in!
推荐答案
我遇到了同样的问题,所以我添加了一个新的Meteor包装器( https://atmospherejs.com/bryanmorgan/webshot )使用最新版本的node-webshot(0.15.4).您应该可以使用:
I had the same problem so I added a new Meteor wrapper (https://atmospherejs.com/bryanmorgan/webshot) using the latest version of node-webshot (0.15.4).You should be able to use:
meteor add bryanmorgan:webshot
以及与node-webshot相同的API:
And the same API as node-webshot:
webshot("http://google.com", "/tmp/google.png", function (err) {
// screenshot saved to /tmp/google.png
});
这篇关于流星网络截图无法将屏幕截图保存到服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!