【问题标题】:I want to detect PDF text with Cloud Vision API and get the result from Google Cloud Storage我想使用 Cloud Vision API 检测 PDF 文本并从 Google Cloud Storage 获取结果
【发布时间】:2020-10-19 10:22:08
【问题描述】:

我想要视觉 API 结果的文件名,但我不知道如何获取。

// Imports the Google Cloud client libraries
const vision = require('@google-cloud/vision').v1;

// Creates a client
const client = new vision.ImageAnnotatorClient();

const gcsSourceUri = `gs://${bucketName}/${fileName}`;
const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`;

const inputConfig = {
  // Supported mime_types are: 'application/pdf' and 'image/tiff'
  mimeType: 'application/pdf',
  gcsSource: {
    uri: gcsSourceUri,
  },
};
const outputConfig = {
  gcsDestination: {
    uri: gcsDestinationUri,
  },
};
const features = [{type: 'DOCUMENT_TEXT_DETECTION'}];
const request = {
  requests: [
    {
      inputConfig: inputConfig,
      features: features,
      outputConfig: outputConfig,
    },
  ],
};

const [operation] = await client.asyncBatchAnnotateFiles(request);
const [filesResponse] = await operation.promise();
const destinationUri =
  filesResponse.responses[0].outputConfig.gcsDestination.uri;
console.log('Json saved to: ' + destinationUri);

“destinationUri”不包括文件名。 例如,当 gcsDestinationUri 为gs:/*****/index/ 时,destinationUri 为gs:/*****/index。 但是,作为结果保存在 GCS 中的文件是output-1-to-1.json

我搜索了 operation Obj 和 filesResponse Obj,我找不到。

谁知道我的问题??

【问题讨论】:

    标签: node.js google-cloud-platform google-cloud-storage google-vision


    【解决方案1】:

    根据官方文档,文件名的格式为output-x-to-y

    gcsDestination.uri - 有效的 Google Cloud Storage URI。桶必须 可由发出请求的用户或服务帐户写入。这 文件名将是 output-x-to-y,其中 x 和 y 代表 PDF/TIFF 该输出文件中包含的页码。如果文件存在,它的 内容将被覆盖。

    But, the file saved as result in GCS is output-1-to-1.json.

    因此,我认为一切都按预期进行,您不能更改文件名。

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 2017-10-20
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      相关资源
      最近更新 更多