Google cloud storage 谷歌云存储意外标识符“;储存;
我发现了这个和这个关于上传文件到谷歌云存储。我写了这段代码:Google cloud storage 谷歌云存储意外标识符“;储存;,google-cloud-storage,Google Cloud Storage,我发现了这个和这个关于上传文件到谷歌云存储。我写了这段代码: const {Storage} = require('@google-cloud/storage')(); const projectId = 'myapp-cd94d'; const storage = new Storage({ projectId: projectId, }); const bucketName = "myapp-cd94d.appspot.com"; const filename = { 'test':
const {Storage} = require('@google-cloud/storage')();
const projectId = 'myapp-cd94d';
const storage = new Storage({
projectId: projectId,
});
const bucketName = "myapp-cd94d.appspot.com";
const filename = { 'test': 'file'};
var serviceAccount = require("./serviceAccountKey.json")
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "myapp-cd94d.appspot.com"
});
var bucket = admin.storage().bucket();
await storage.bucket(bucketName).upload(filename, {
gzip: true,
metadata: {
cacheControl: 'no-cache',
},
});
console.log(`${filename} uploaded to ${bucketName}.`);
我尝试部署代码,但收到以下错误消息:
await storage.bucket(bucketName).upload(filename, {
^^^^^^^
SyntaxError: Unexpected identifier
我的第一行有什么问题吗
const {Storage} = require('@google-cloud/storage')();
为什么存储
周围有花括号?我应该用别的东西来替换{Storage}
吗
为什么在储藏室周围有花括号?我应该用别的东西来代替{Storage}吗
存储
周围的花括号表示存储。它允许您从存储在对象和数组中的数据中提取多个值。从(const{Storage}=require('@googlecloud/Storage');
导入的示例是正确的
错误消息SyntaxError:Unexpected identifier
并不是说它没有识别存储
,而是说它不希望存储
在那里。该错误是由于wait
引起的
只能在异步
函数中使用。例如:
async function myAsyncFunction() {
let result = await lengthyFunction();
console.log(result);
}
myAsyncFunction();
尝试将bucket upload调用包装在
async
函数中,以避免在使用wait
I开始编写“未识别的期望值”而不是“意外标识符”时出错。可能是丢失的手帕?:-)@托马斯戴维克霍不用担心,恰巧是最好的哈哈