title: NodeJS: Trying to upload a file to a user's Firebase storage bucket once it has been processed by an API
body: <p>I'm trying to upload a file to a user's Firebase storage bucket once it has been processed by an API i'm working with. I'm doing this from the server side.</p>
  <p>The issue here is that I need to reference the UID from the backend in order to send it across to firebase.</p>
  <p>I've got everything working with the API but when I try to initiate Firebase it throws-back an error about it not being initialised. I have already initialised Firebase in my start.js and referenced Firebase in the file that I'm writing the code in. I guess I could call it via 'admin.firebase' but not sure if that makes sense as I want the users to upload via their uid. Any help would be awesome</p>
  <p>Here is the post request initialising the API from the backend. The point i'm trying to initialise the firebase upload is where i call 'console.log(JOB COMPLETE)':</p>
  <pre><code>const fs = require('fs');
  const express = require('express');
  const multer = require('multer');
  const axios = require('axios');
  const firebase = require(&quot;firebase/app&quot;);
  const admin = require(&quot;firebase-admin&quot;);
  const storage = require(&quot;firebase/storage&quot;);
  const auth = require(&quot;firebase/auth&quot;);
  
  
  const
  {
    BucketsApi,
    ObjectsApi,
    PostBucketsPayload,
    DerivativesApi,
    JobPayload,
    JobPayloadInput,
    JobPayloadOutput,
    JobSvfOutputPayload
  } = require('forge-apis');
  
  const
  {
    getClient,
    getInternalToken
  } = require('./common/oauth');
  const config = require('../config');
  
  let router = express.Router();
  
  // Middleware for obtaining a token for each request.
  router.use(async (req, res, next) =&gt;
  {
    const token = await getInternalToken();
    req.oauth_token = token;
    req.oauth_client = getClient();
    next();
  });
     
  
   router.post('/objects', multer(
  {
    dest: 'uploads/'
  }).single('fileToUpload'), async (req, res, next) =&gt;
  {
  
    fs.readFile(req.file.path, async (err, data) =&gt;
    {
      if (err)
      {
        next(err);
      }
      try
      {
        // Upload an object to bucket using [ObjectsApi](https://github.com/Autodesk-Forge/forge-api-nodejs-client/blob/master/docs/ObjectsApi.md#uploadObject).
        const response = await new ObjectsApi().uploadObject(req.body.bucketKey, req.file.originalname, data.length, data,
        {}, req.oauth_client, req.oauth_token);
        if (response.statusCode === 200)
        {
          let buff = Buffer(response.body.objectId)
          let job = new JobPayload();
          job.input = new JobPayloadInput();
          job.input.urn = buff.toString('base64');
          job.output = new JobPayloadOutput([
            new JobSvfOutputPayload()
          ]);
          job.output.formats[0].type = 'svf';
          job.output.formats[0].views = ['2d', '3d'];
          try
          {
            console.log('translating');
            const token = req.oauth_token.access_token;
  
            // Submit a translation job using [DerivativesApi](https://github.com/Autodesk-Forge/forge-api-nodejs-client/blob/master/docs/DerivativesApi.md#translate).
            await new DerivativesApi().translate(job,
            {}, req.oauth_client, req.oauth_token);
            setInterval(function()
            {
              console.log('polling');
              var config = {
                method: 'get',
                url: 'https://developer.api.autodesk.com/modelderivative/v2/designdata/' + buff.toString('base64') + '/manifest',
                headers:
                {
                  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:84.0) Gecko/20100101 Firefox/84.0',
                  'Accept': '*/*',
                  'Accept-Language': 'en-GB,en;q=0.5',
                  'Authorization': 'Bearer ' + token,
                  'Origin': 'http://localhost:3000',
                  'Connection': 'keep-alive',
                  'Referer': 'http://localhost:3000/view',
                  'Pragma': 'no-cache',
                  'Cache-Control': 'no-cache'
                }
              };
  
              axios(config)
                .then(function(response)
                {
                  response = response.data;
                  console.log(response.progress, response.status);
                  if (response.progress === &quot;complete&quot;)
                  {
                    if (response.status === &quot;success&quot;)
                    {
                      console.log(&quot;JOB COMPLETE&quot;);
                    }
  
                  }
  
                })
                .catch(function(error)
                {
                  console.log(error);
                  return;
                });
            }, 2000);
            res.status(200).end();
          }
          catch (err)
          {
            next(err);
            return;
          }
        }
        else
        {
          console.log('bad')
          res.status(response.statusCode).end(response);
        }
      }
      catch (err)
      {
        next(err);
        return;
      }
    });
  });
  </code></pre>