title: Firebase Admin SDK Upload File to Google Cloud Storage
body: <p>This has been a source of frustration for the past couple of days because the documentation makes it sound like it should be straightforward.</p>
  <p>I have a simple HTTP server running locally (Heroku eventually) that I want to use as a passthrough to upload a file to Firebase Cloud Storage. I have a credentials file and am able to successfully init the Firebase App and validate JWTs, but when I try to put an object, I always get an error.</p>
  <p>Here is the code --</p>
  <pre><code>func main() {
     config := &amp;firebase.Config{
        ProjectID:     &quot;myproject-id&quot;,
        StorageBucket: &quot;myproject-id.appspot.com&quot;,
     }
     credentialsJSON := os.Getenv(&quot;GOOGLE_CREDENTIALS&quot;)
     creds := google.Credentials{JSON: []byte(credentialsJSON)}
     opt := option.WithCredentials(&amp;creds)
  
     app, err := firebase.NewApp(context.Background(), config,
      opt)
  
     if err != nil {
       log.Fatalln(err)
     }
     ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
     defer cancel()
  
     client, err := app.Storage(ctx)
     if err != nil {
       log.Fatalln(err)
     }
     fmt.Println(client)
  
     bucket, err := client.DefaultBucket()
  
     object := bucket.Object(&quot;foo.png&quot;)
     wc := object.NewWriter(ctx)
  
     r, err := os.Open(&quot;/Users/foo/test.png&quot;)
     defer r.Close()
  
     if _, err = io.Copy(wc, r); err != nil {
        log.Error(err)
     }
  
     if err := wc.Close(); err != nil {
       fmt.Println(err)
       log.Error(err)
     }
  }
  </code></pre>
  <p>But this is what I get when I run this code --</p>
  <pre><code> Post &quot;https://storage.googleapis.com/upload/storage/v1/b/myproject-id.appspot.com/o?alt=json&amp;name=foo.png&amp;prettyPrint=false&amp;projection=full&amp;uploadType=multipart&quot;: oauth2: Transport's Source is nil
  </code></pre>
  <p>The Firebase Admin SDK documentation clearly states that the service account has full scope control on the storage account, but it seems like there is some mistake on bootstrapping the credentials correctly since the Transport token source is nil.</p>