skip to Main Content

I followed the instructions and I created the ServiceAccountKey.json but when I try to upload a file to the Firebase Storage, I get an exception: "Be careful, this may be a production service".

enter image description here

Node.js 16

  cupertino_icons: ^1.0.2
  firebase_core: ^1.24.0
  firebase_database: ^9.1.6
  video_player: ^2.4.7
  camera: ^0.10.0+3
  cloud_firestore: ^3.5.1
  firebase_auth: ^3.11.2
  dio: ^4.0.6
  flutter_cors: ^1.3.2
  convert: ^3.0.2
  flutter_signin_button: ^2.0.0
  google_sign_in: ^5.4.2
  path_provider: ^2.0.2
  firebase_storage: ^10.3.11

The code:

var admin = require("firebase-admin");
    
var serviceAccount = require("./serviceAccountKey.json");
    
admin.initializeApp({
           credential: admin.credential.cert(serviceAccount),
           databaseURL: "https://123-default-rtdb.firebaseio.com"
});
    
    
exports.saveVideoOnStorage = functions.https.onRequest(async (req, res) => {
    inputFile = '/Users/nativvered/pubspec.yaml';
    const myStorage = admin.storage();
    const bucket = admin.storage().bucket('gs://123.appspot.com/Files');

    await bucket.upload(inputFile);
});

The exception:

Google API requested!
   - URL: "https://www.googleapis.com/oauth2/v4/token"
   - Be careful, this may be a production service.
⚠  Google API requested!
   - URL: "https://storage.googleapis.com/upload/storage/v1/b/challenge-me-vn.appspot.com/Videos/o?uploadType=multipart&name=pubspec.yaml"
   - Be careful, this may be a production service.
⚠  functions: Error: Not Found
    at new ApiError (/Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/@google-cloud/storage/build/src/nodejs-common/util.js:78:15)
    at Util.parseHttpRespMessage (/Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/@google-cloud/storage/build/src/nodejs-common/util.js:180:41)
    at Util.handleResp (/Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/@google-cloud/storage/build/src/nodejs-common/util.js:154:76)
    at /Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/@google-cloud/storage/build/src/nodejs-common/util.js:500:22
    at onResponse (/Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/retry-request/index.js:228:7)
    at /Users/nativvered/Documents/MyFlluter/vered2/functions/node_modules/teeny-request/build/src/index.js:157:17
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
⚠  Your function was killed because it raised an unhandled error.

2

Answers


  1. Chosen as BEST ANSWER

    The problem was that the bucket is gs://123.appspot.com/ and not gs://123.appspot.com/Files


  2. "Be careful, this may be a production service." is not an error, but a warning that your local emulator is not talking to an emulated storage API.

    The actual error is "Error: Not Found" which is because the file you want to upload cannot be found or is not accessible. In your case, you cannot upload the file at /Users/nativvered/pubspec.yaml because it is located outside of your functions directory.

    You have two options:

    • You need to send the file you want to upload in the body of the request you are making to your saveVideoOnStorage function in the code that is calling the function. (recommended)
    • You copy the pubspec.yaml into your functions directory before starting up the emulator and then upload it from there. (not recommended, but useful for testing)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search