我有一个从onCreate Firestore DB触发器运行的Firebase函数。然后,该函数需要创建一个目录(以及存储桶中最终的临时文件),但是每当我尝试创建存储桶时,都会收到错误消息(从“ CLoud Functions”控制台发出):
[
{ domain: 'global',
reason: 'forbidden',
message: 'The bucket you tried to create requires domain ownership verification.' }
]
不是Cloud Functions始终具有创建存储桶等的功能,因为它正在从Functions服务器访问其自己的资源。根本不知道为什么会这样。
这是我正在运行的代码:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
admin.initializeApp()
const functions = require('firebase-functions')
const admin = require("firebase-admin")
const {Storage} = require('@google-cloud/storage')
// const spawn = require('child-process-promise').spawn;
const path = require('path')
const os = require('os')
const fs = require('fs')
exports.packUp = functions.firestore.document('/packs/{packId}').onCreate((snapShot, context) => {
const packId = snapShot.id
console.info("STARTING PACK for packId", packId)
const bucketName = 'mybucket.appspot.com'
const projectId = 'myapp-dev'
// USING New v2 API https://www.npmjs.com/package/@google-cloud/storage
const storage = new Storage({
projectId: projectId,
});
const fileName = packId + ".pdf"
const filePath = '/quiverPacks/' + packId
const tmpFilePath = path.join(os.tmpdir(),fileName)
const cconvert = new (require('cloudconvert'))('myKey')
storage.createBucket(bucketName)
.then(() => {
console.log('Bucket ${bucketName} created.');
// cconvert.convert({
// "inputformat": "*",
// "outputformat": "pdf",
// "mode": "combine",
// "input": "download",
// "files": [
// "https://cloudconvert.com/assets/4e6b2989/testfiles/pdfexample1.pdf",
// "https://cloudconvert.com/assets/4e6b2989/testfiles/pdfexample2.pdf"
// ],
// "preset": "21yvMij5Xz",
// "download": true,
// "wait": true,
// "save": true
// })
// .pipe(fs.createWriteStream(tmpFilePath))
// .catch( function(err) {
// console.error('ERROR:', err)
// });
})
.catch( function(error) {
console.error('ERROR:', error)
})
})
如果需要,这是完整的错误堆栈:
ERROR: { Error: The bucket you tried to create requires domain ownership verification.
at ApiError (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:43:9)
at Util.parseHttpRespBody (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:190:38)
at Util.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:134:117)
at retryRequest (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/build/src/util.js:422:22)
at onResponse (/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:200:7)
at /user_code/node_modules/@google-cloud/storage/node_modules/teeny-request/build/src/index.js:222:13
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
code: 403,
errors:
[ { domain: 'global',
reason: 'forbidden',
message: 'The bucket you tried to create requires domain ownership verification.' } ],
response: undefined,
message: 'The bucket you tried to create requires domain ownership verification.' }
在此先感谢任何可以帮助您的人!