我正在尝试将在Firebase云功能中创建的zip文件上传到Firebase存储。我的代码设置如下:
const appConfig = {
credential: admin.credential.cert(ServiceAccount),
databaseURL: 'https://xxx.firebaseio.com',
storageBucket: 'https://xxx.firebaseio.com',
};
const app = admin.initializeApp(appConfig);
export const db = app.firestore();
export const auth = app.auth();
export const storage = app.storage().bucket();
然后我将存储导入到函数中并运行以下命令:
const options = {
gzip: true,
uploadType: 'media',
destination: `${filename}.zip`,
metadata: {
metadata,
contentType: 'application/zip',
cacheControl: 'public, max-age=31536000',
},
};
const storageData = await storage.upload(file, options)
.catch((error) => {
throwError('unknown', 'Error uploading exported data to store', error);
});
尝试上传文件时,出现以下错误。
error: { Error: Cannot parse JSON response
at Util.parseHttpRespBody (functions/node_modules/@google-cloud/common/build/src/util.js:167:42)
at Util.handleResp (functions/node_modules/@google-cloud/common/build/src/util.js:116:117)
at retryRequest (functions/node_modules/@google-cloud/common/build/src/util.js:404:22)
at onResponse (functions/node_modules/retry-request/index.js:200:7)
at functions/node_modules/teeny-request/build/src/index.js:158:17
at process._tickCallback (internal/process/next_tick.js:68:7) message: 'Cannot parse JSON response' }
看来Util.parseHttpRespBody
正在收到“找不到”正文。我见过类似的问题,但它们似乎都与存储桶名称有关。我使用的是默认存储桶,有点迷路。我想念什么?为什么将存储调用的主体设置为“未找到”?