【发布时间】:2014-08-17 23:33:39
【问题描述】:
在服务器上,我想截取外部链接的屏幕截图并将其保存到服务器的文件夹中。
我正在尝试将包 webshot 用于流星:
https://github.com/TimHeckel/meteor-webshot
但它不起作用。我使用 mrt add webshot 安装了该软件包。包安装成功。根据这个stackoverflow:How to use webshot with meteor
我能够编辑 webshot 的 package.js 文件以导出 WEBSHOT 变量服务器端,如下所示:
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
});
这是我调用服务器端拍摄网页的代码:
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~ 的目录,当我运行我的代码时,没有图像保存到该目录中,并且我没有收到任何错误。我不知道发生了什么!
由于我已经设置了我的流星以便能够在服务器端安装 npm 包,我还尝试通过使用常规的旧 npm install webshot 安装来使用 npm webshot 包。
然后我尝试使用 webshot = Meteor.require('webshot') 但它从未奏效,因为我无法启动应用程序,因为它不断崩溃并出现以下错误:
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。但是我终于在使用meteor smart package时让它工作了,只要我添加
api.export("WEBSHOT","server");
到 webshot 的 package.js 文件。但它仍然没有实际截取屏幕截图。请有人提示我!
【问题讨论】:
标签: node.js meteor phantomjs meteorite