firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.77k stars 874 forks source link

Unable to Upload Files Larger than 2GB to Firebase Storage #8321

Closed kevinrss01 closed 2 weeks ago

kevinrss01 commented 3 weeks ago

Operating System

MAC OS SONOMA 14.5

Browser Version

ARC (CHROME)

Firebase SDK Version

10.12.2

Firebase SDK Product:

Storage

Describe your project's tooling

I'm using nestJS (@10.3.9), nodeJS (v20.11.1)

Describe the problem

I am experiencing an issue where attempting to upload files larger than 2GB to Firebase Storage results in a GaxiosError: request to https://storage.googleapis.com/upload/storage/v1/b/[...] failed, reason: write EPROTO.

However, smaller files (e.g., 1.8GB) upload without any issues.

Steps and code to reproduce issue

  1. Attempt to upload a file larger than 2GB using the Firebase Storage SDK in a Node.js application.
  2. Encounter the following error: Failed to upload file. GaxiosError: request to [https://storage.googleapis.com/upload/storage/v1/b/[](https://storage.googleapis.com/upload/storage/v1/b/%5B)...] failed, reason: write EPROTO at Gaxios._request (/path/to/project/node_modules/gaxios/src/gaxios.ts:157:13) type: 'system', errno: 'EPROTO', code: 'EPROTO'

Code Sample

Here is a sample of the TypeScript function used for uploading:

import { Stream } from 'stream';
import { getStorageAdmin } from 'path-to-your-storage-admin-utils';

async uploadFileViaStream(fileStream: Stream, path: string): Promise<string> {
    console.debug('Uploading file to storage using stream...');
    const storage = getStorageAdmin();
    const bucket = storage.bucket('voicecheap-c1f14.appspot.com');
    const fileRef = bucket.file(path);
    const contentType =
      path.split('.').pop() === 'mp3' ? 'audio/mpeg' : 'video/mp4';

    // Verify if the file already exists
    const [exists] = await fileRef.exists();
    if (exists) {
      console.debug('File already exists. Skipping upload.');
      return fileRef.publicUrl();
    }

    return new Promise((resolve, reject) => {
      fileStream
        .pipe(
          fileRef.createWriteStream({
            contentType: contentType,
            public: true,
            metadata: {
              contentType: contentType,
              mimeType: contentType,
              type: contentType,
            },
          }),
        )
        .on('error', (error) => {
          console.error('Failed to upload file.', error);
          reject(error);
          throw new InternalServerErrorException('Failed to upload file.');
        })
        .on('finish', async () => {
          // Make the file publicly accessible
          try {
            await fileRef.makePublic();
            console.debug('File uploaded and made public.');
            resolve(fileRef.publicUrl());
          } catch (error) {
            console.error('Failed to make the file public.', error);
            reject(error);
            throw new InternalServerErrorException(
              'Failed to make the file public.',
            );
          }
        });
    });
  }
dlarocque commented 2 weeks ago

Hi @kevinrss01, are you using the Firebase Admin SDK? We don't seem to support uploading files over 2GB #6524.

kevinrss01 commented 2 weeks ago

@dlarocque Hi, yes I am using Firebase Admin SDK. Are you sure? The error does not indicate a file size problem..

dlarocque commented 2 weeks ago

@dlarocque Hi, yes I am using Firebase Admin SDK. Are you sure? The error does not indicate a file size problem..

If you are having issues with the Firebase Admin SDK, please report this issue in their Github repo https://github.com/firebase/firebase-admin-node

(I tried transferring the issue to their repo but I don't have permissions :p)