从Google云功能设置Firebase存储的位置路径?

从Google云功能设置Firebase存储的位置路径?,firebase,google-cloud-platform,firebase-storage,Firebase,Google Cloud Platform,Firebase Storage,我正在将一个音频文件从谷歌文本转换成语音,然后将该文件写入Firebase存储。我不明白在何处指定存储位置的路径。我试过: const bucket=storage.bucket('myProject-cd99d.appspot.com/Audio/西班牙语/test.ogg'); 但我收到一条错误消息:TypeError:Path必须是字符串。以下是云函数: exports.Google_T2S=functions.firestore.document('Users/{userID}/Sp

我正在将一个音频文件从谷歌文本转换成语音,然后将该文件写入Firebase存储。我不明白在何处指定存储位置的路径。我试过:


const bucket=storage.bucket('myProject-cd99d.appspot.com/Audio/西班牙语/test.ogg');
但我收到一条错误消息:
TypeError:Path必须是字符串。以下是云函数:

exports.Google_T2S=functions.firestore.document('Users/{userID}/Spanish/T2S_Request').onUpdate((更改,上下文)=>{
if(change.after.data().word!=未定义){
//执行文本到语音的请求
异步函数测试(){
试一试{
const word=change.after.data().word;//文本
const longluage=‘西班牙语’;
const audioFormat='.mp3';
//抄袭https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries#client-图书馆使用节点
常数fs=要求('fs');
const util=require('util');
const textToSpeech=require(“@google cloud/text-to-speech”);//导入google cloud客户端库
const client=new textToSpeech.TextToSpeechClient();//创建一个客户端
让myWordFile=word.replace(//g,“”);//在文件名中用下划线替换空格
myWordFile=myWordFile.toLowerCase();//将文件名转换为小写
myWordFile=myWordFile+audioFormat;//在文件名后追加.mp3;
//抄袭自https://cloud.google.com/blog/products/gcp/use-google-cloud-client-libraries-to-store-files-save-entities-and-log-data
const{Storage}=require('@googlecloud/Storage');
常量存储=新存储();
const bucket=storage.bucket('myProject-cd99d.appspot.com/Audio/西班牙语/test.ogg');
const request={//构造请求
输入:{text:word},
//选择语言和SSML语音性别(可选)
声音:{语言代码:'es es',SSMLSENDER:'女性'},
//选择音频编码的类型
audioConfig:{audioEncoding:'MP3'},
};
const[response]=等待客户端合成语音(请求);
//将二进制音频内容写入本地文件
//response.audioContent是下载的文件
等待bucket.upload(response.audioContent{
元数据:“公共,最大年龄=31536000”
})
.然后(函数(){
log(“上传的文件”);
})
.catch(函数(错误){
控制台错误(error);
});
}
捕获(错误){
控制台错误(error);
}
}
test();
}//如果关闭,则关闭
返回0;
});

我还需要返回main函数。

在云存储中,bucket指的是文件存放的容器。它不引用文件本身。看起来您假设一个bucket实际上是一个文件,这是不正确的

您的bucket名称如下:

const bucketName = 'myProject-cd99d.appspot.com'
该存储桶中的文件路径如下:

const filePath = '/Audio/Spanish/test.ogg'
您构建的对象如下所示:

const bucket = storage.bucket(bucketName)
然后使用Bucket上的方法将文件上载到该路径:

bucket.upload(response.audioContent, {
    destination: filePath
})

一定要点击API文档的所有链接,以便更好地了解API的工作原理。

Doug,bucket.upload()的API文档说,第一个参数是要上传的文件:上传(pathString、options、callback)要上传到bucket的文件的完全限定路径。你说,“然后使用Bucket上的upload()方法将文件上传到该路径:”我想你的意思是“将文件从该路径上传到Bucket”。我写了一个新问题,我们期待你的回答:我在这里编辑了答案以反映正确的用法。