我想获取触发 oncreate 函数的文档的 ID,但我尝试snap.params.id
如下,但未定义。
当我控制台记录这个时projectId
,我得到未定义,有时会抛出错误,我使用版本“firebase-admin”:“~5.12.1”,“firebase-functions”:“^1.0.3”
exports.created = functions.firestore.document('projects/{projectId}')
.onCreate(snap => {
const projectId = snap.params.id;
const project = snap.data();
const notification = {
title: `${project.title}`,
projectId: `${projectId}`
}
});
Run Code Online (Sandbox Code Playgroud)
那么如何获取文档ID呢?
在我所有的分享按钮中,我的图片不只显示网址
在我的公共文件夹 html 标题中
<meta content="`%PUBLIC_URL%/${picture.jpg}`">
<meta property="og:description" content='' />
Run Code Online (Sandbox Code Playgroud)
在我的详细信息组件中,我使用 react-helmet t 动态地将标题放在共享按钮的位置。
render() {
const { project, auth } = this.props;
const shareUrl = window.location.href;
const articleId = this.props.match.params.id;
const {pathname} = this.props.location;
const imageURL = '';
if (project) {
return (
<div className="container">
Run Code Online (Sandbox Code Playgroud)
头盔组件
<Helmet>
<meta charSet="utf-8" />
<title>{project.title}</title>
<meta property="og:url" content={`https://l.facebook.com/l.php?u=https%3A%2F%2F${shareUrl?shareUrl:''}`} />
<meta property="og:description" content={project.title} />
<meta property="og:image" content={imageURL!==''?`${project.pictureUrl}`: ''} />
<meta property="fb:app_id" content="198985484382564" />
</Helmet>
Run Code Online (Sandbox Code Playgroud)
当分享到脸书时,我得到了什么
只是图片网址,但图片没有显示。
<FacebookShareButton
url={shareUrl}
imageURL={project.pictureUrl}
quote={project.title} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现云功能,但是如果我需要这样会出错
var storage =require('@google-cloud/storage')();
Run Code Online (Sandbox Code Playgroud)
部署时是这样的
var storage = require('@google-cloud/storage');
Run Code Online (Sandbox Code Playgroud)
所以我决定使用上面的方法,但是尝试上传图片时出现错误“ TypeError:gcs.bucket不是函数”
const os = require('os');
const path = require('path');
Run Code Online (Sandbox Code Playgroud)
///
exports.onFileChange = functions.storage.object().onFinalize((event) => {
const bucket = event.bucket;
const contentType = event.contentType;
const filePath = event.name;
console.log('Changes made to bucket');
Run Code Online (Sandbox Code Playgroud)
///
if(path.basename(filePath).startsWith('renamed-')){
console.log("File was previously renamed");
return;
}
const gcs = storage({
projectId: 'clfapi'
});
Run Code Online (Sandbox Code Playgroud)
///
const destBucket = gcs.bucket(bucket);
const tmFiilePath = path.join(os.tmpdir(), path.basename(filePath));
const metadata = {contentType: contentType};
Run Code Online (Sandbox Code Playgroud)
///
return destBucket.file(filePath).download({
destination: tmFiilePath
}).then(() => {
return …
Run Code Online (Sandbox Code Playgroud)