0

I know there many duplicates which ask similar questions but for the past 2 hours I have tried and surfed the internet for a single line of code has piled my frustration. I am sorry but please help me out. Here is what I have tried up until now, it gives this error:

Error

38:22 error Parsing error: Unexpected token firebase

Code

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const spawn = require('child-process-promise').spawn;
const path = require('path');
const os = require('os');
const fs = require('fs');

exports.getDownloadUrl = functions.region("asia-south1").storage.object().onChange(event => {
  const object = event.data;
    const fileBucket = object.bucket;
    const filePath = object.name;
    const bucket = gcs.bucket(fileBucket);
    const contentType = object.contentType;
    const resourceState = object.resourceState;
    const tempFilePath = '/test/air.jpg';

    return {
      message: await firebase.storage().ref(tempFilePath).getDownloadUrl // line 38
    };
});

I just want to get a download url from the given file path.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • There is no `getDownloadUrl` in the Node.js SDK. Instead you'll want to generate a so-called signed URL. See https://stackoverflow.com/search?q=%5Bfirebase-storage%5D%5Bgoogle-cloud-functions%5D+get+download+url – Frank van Puffelen Sep 18 '20 at 15:27
  • The error message primarily comes from the fact that you didn't define the variable `firebase` anywhere in your code. But even if you did import the Firebase web client SDK in your code, you wouldn't be able to use it this way. You will need to use the nodejs API for Cloud Storage as shown in the duplicate. – Doug Stevenson Sep 18 '20 at 16:01

0 Answers0