firebase / firebase/firebase-admin-node
Unable to Upload Files Larger than 2GB to Firebase Storage
- 主要语言
- TypeScript
- 星标
- 1.7k
- 派生
- 419
- 平均合并
- 3 天 10 小时
- 30 天内合并 PR
- 16
描述
### [REQUIRED] Step 2: Describe your environment
**Operating System**
- MAC OS SONOMA 14.5
**Browser Version**
- ARC (CHROME)
**Firebase SDK Version**
- 10.12.2
**Firebase SDK Product:**
- Storage
**NPM and NODE:**
I'm using nestJS (@10.3.9), nodeJS (v20.11.1) and npm 10.2.4
### [REQUIRED] Step 3: 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 to reproduce:
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/...] failed, reason: write EPROTO
at Gaxios._request (/path/to/project/node_modules/gaxios/src/gaxios.ts:157:13)
type: 'system',
errno: 'EPROTO',
code: 'EPROTO'
```
#### Relevant Code:
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 {
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.',
);
}
});
});
}
```
贡献指南
调研方向
从提供的 uploadFileViaStream 函数开始,在 Node.js 上使用一个超过 2GB 的文件重现 Firebase Storage SDK 10.12.2 中的失败,然后将其与所述的 1.8GB 情况进行比较。跟踪 Gaxios EPROTO 请求,以确定问题是在 SDK 的上传路径中,还是在其使用方式中;当原因和受支持的解决方案得到明确确立时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- firebase, node.js, typescript
- 领域
- backend, cloud
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100