Nodejs fs.createReadStream无法读取Firebase Storage下载URL“ ENOENT:无此类文件或目录”

问题描述 投票:0回答:1

documentationfs.createReadStream(path)表示它可以读取URL:

path <string> | <Buffer> | <URL>

文档显示path周围的引号:

fs.createReadStream('/dev/input/event0');

但是当我输入此Firebase Storage下载URL时

fs.createReadStream('https://firebasestorage.googleapis.com/v0/b/languagetwo-cd94d.appspot.com/o/Users%2FbcmrZDO0X5N6kB38MqhUJZ11OzA3%2Faudio-file.flac?alt=media&token=871b9401-c6af-4c38-aaf3-889bb5952d0e'),

我收到错误消息ENOENT: no such file or directory。您可以单击该URL并听到它起作用:

https://firebasestorage.googleapis.com/v0/b/languagetwo-cd94d.appspot.com/o/Users%2FbcmrZDO0X5N6kB38MqhUJZ11OzA3%2Faudio-file.flac?alt=media&token=871b9401-c6af-4c38-aaf3-889bb5952d0e

我也尝试过Google Storage URI:

fs.createReadStream('gs://languagetwo-cd94d.appspot.com/Users/bcmrZDO0X5N6kB38MqhUJZ11OzA3/audio-file.flac'),

这没用。我必须使用https.request发出HTTP GET请求吗?

这是我的完整代码,复制自IBM Cloud Speech-to-Text API docs

const fs = require('fs');
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const speechToText = new SpeechToTextV1({
   authenticator: new IamAuthenticator({
      apikey: 'my-api-key',
      }),
   url: 'https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/01010101',
});

var params = {
   audio: fs.createReadStream('https://firebasestorage.googleapis.com/v0/b/languagetwo-cd94d.appspot.com/o/Users%2FbcmrZDO0X5N6kB38MqhUJZ11OzA3%2Faudio-file.flac?alt=media&token=871b9401-c6af-4c38-aaf3-889bb5952d0e'),
   contentType: 'audio/flac',
   wordAlternativesThreshold: 0.9,
   keywords: ['colorado', 'tornado', 'tornadoes'],
   keywordsThreshold: 0.5,
};

speechToText.recognize(params)
.then(results => {
   console.log(JSON.stringify(results, null, 2));
})
.catch(err => {
   console.log('error:', err);
});
node.js firebase-storage
1个回答
0
投票

如果看到here,则明确提到它仅支持file://协议。 http/https不支持。

我不建议使用requestrequest-promise,因为它们已被弃用。我建议使用一些现代库,例如gotaxios等。>

© www.soinside.com 2019 - 2024. All rights reserved.