【发布时间】:2017-09-30 03:25:06
【问题描述】:
这已在 GOOGLE 端解决了
Google Cloud NodeJs 库现已修复集成。保留这个问题仅供参考。
原始问题
我希望我的代码更简洁,并使用 Typescript 和 async/await 编写访问 Google Cloud Storage 的 Cloud Functions。
我tsconfig.json的一些重要部分:
{
"compilerOptions": {
"declaration": false,
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"sourceMap": false,
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016"
],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "./"
}
}
我遇到的第一个错误是ECONNRESET,我正在拨打这样的电话,这可能是导致它的原因:
await bucket.file(path).download({
destination: tempFilePath
})
我认为函数的其余部分没有等到这一行完成并且整个函数执行结束之前文件从 GCS 下载到临时路径。 所以我把那个部分放到了 try/catch 块中:
try {
await bucket.file(path).download({
destination: tempFilePath
})
} catch (error) {
console.log(error);
}
直到今天它都运行良好。今天我遇到了这个错误:
convert: Empty input file '/temp/img-file.jpg'
这再次让我想到在文件从存储桶下载到临时文件夹之前执行下一行(转换图像大小)。
我错过了什么吗?
【问题讨论】:
-
您确定该文件存在吗?
-
@m_callens 在通话之前添加
console.log,很快就会通知您。 -
每次打印正确的路径并且我已经进行了 6 次测试,现在都可以正常工作。部署功能后是否需要等待一段时间?我在部署后的一分钟内进行了测试并出现了错误(当时我出现了错误),现在似乎一切正常。
-
今天我遇到了这个错误:
code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read'我要回到 Promise-Land 并放弃 async/await
标签: javascript node.js asynchronous google-cloud-storage google-cloud-functions