【问题标题】:firestore admin upload file Error: Not Foundfirestore 管理员上传文件错误:未找到
【发布时间】:2021-01-23 16:49:50
【问题描述】:

我正在尝试使用 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的同一目录下,即根目录。是不是我指定的路径不对?

【问题讨论】:

标签: javascript node.js firebase google-cloud-storage firebase-storage


【解决方案1】:

我没有成功使用 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)
    }
});

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 1970-01-01
    • 2015-10-30
    • 2011-01-21
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2019-12-24
    • 2017-11-25
    相关资源
    最近更新 更多