如何解决firestore管理员上传文件错误:找不到
我正在尝试使用node.js后端中的Admin SDK将图像上传到Firebase的Cloud Firestore。以下是我的代码:
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),storageBucket: "something.appspot.com.appspot.com"
});
var bucket = admin.storage().bucket();
bucket.upload('ns_icon.png').then(() => {
console.log("uploaded");
})
下面的代码会产生错误消息:
server is running on port: 8000
(node:37108) UnhandledPromiseRejectionWarning: Error: Not Found
at new ApiError (C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\@google-cloud\common\build\src\util.js:59:15)
at Util.parseHttpRespBody (C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\@google-cloud\common\build\src\util.js:194:38)
at Util.handleResp (C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\@google-cloud\common\build\src\util.js:135:117)
at C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\@google-cloud\common\build\src\util.js:434:22
at onResponse (C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\retry-request\index.js:214:7)
at C:\Users\PC\OneDrive - University of Waterloo\Hugue\Startups\Pllanet\Tech\Admin Console\node_modules\teeny-request\build\src\index.js:150:17
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:37108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting
a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:37108) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
具有上载代码的文件位于ns_icon.png
的同一目录中,该目录是根目录。我指定的路径错误吗?
解决方法
我没有使用Firebase管理员成功上传文件。但是我可以使用Google Cloud进行如下操作:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
projectId: 'xxxxx',keyFilename: 'serviceAccount.json'
});
const bucket = storage.bucket("zzzzz");
// Upload a local file to a new file to be created in your bucket.
bucket.upload('ns_icon.png',function(err,file) {
if (!err) {
console.log("success");
}
else {
console.log(err)
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。