title: How to create a file with public access
body: <p>I need to upload a file to Google Cloud Storage and make it public immediately.
  I use <code>createWriteStream</code>.
  If I try to write a file and after a finish immediately call <code>makePublic</code> - I get an error about that no such object.
  For now, I use setTimeout with <code>makePublic</code> callback, but it's a hacky way.</p>
  
  <p>the code looks like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const name = 'folder/file.jpg'
  const fileRef = bucket.file(name)
  
  const save = (stream, name, meta) =&gt; 
    new Promise((resolve, reject) =&gt; {
      stream
        .on('error', (error) =&gt; reject(error)})
        .on('end', () =&gt; resolve(name))
        .pipe(fileRef.createWriteStream({
          metadata: meta,
        }))
    })
  
  save(yourReadStream(), name, yourMetaObj)
  .then(() =&gt; {
    setTimeout(() =&gt; {
      fileRef.makePublic()
    }, 1500)
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>How to avoid setTimeout and do it in a guaranteed way?</p>