【发布时间】:2019-01-22 18:39:30
【问题描述】:
包pdf-text-extract 需要一个绝对文件路径。我需要在 Google Cloud Storage 存储桶中的文件上使用这个包。
有没有办法将 GCS 存储桶中的文件作为绝对 URL 传递?
这是我的代码(Node.js):
var storage = require('@google-cloud/storage')();
const extract = require('pdf-text-extract');
const bucketFile = 'http://bucketname.storage.googleapis.com/fileName.pdf';
extract(bucketFile,
(err, pages) => {
if (err) {
console.error(err)
return
}
console.log(pages);
}
);
这会返回一个错误:
Error: pdf-text-extract command failed: I/O Error: Couldn't open file 'D:\Libraries\Documents\pdf-text-extract-bucket\http:\bucketname.storage.googleapis.com\fileName.pdf'
我也尝试将其传递给提取函数:
file = storage.bucket('bucketname').file('fileName.pdf');
它使用本地文件(而不是 GCS 存储桶)的方式:
const filePath = path.join(__dirname, tempFileName);
extract(filePath, callback);
【问题讨论】:
标签: node.js pdf path google-cloud-storage filepath