firebase / firebase/firebase-admin-node
Unable to Upload Files Larger than 2GB to Firebase Storage
- Ngôn ngữ chính
- TypeScript
- Star
- 1.7k
- Fork
- 419
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 16
Mô tả
### [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.',
);
}
});
});
}
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với hàm uploadFileViaStream được cung cấp và tái hiện lỗi trong Firebase Storage SDK 10.12.2 trên Node.js bằng một tệp lớn hơn 2GB, sau đó so sánh với trường hợp 1.8GB đã nêu. Truy vết yêu cầu Gaxios EPROTO để xác định liệu vấn đề nằm trong đường dẫn tải lên của SDK hay trong cách sử dụng SDK; được xem là hoàn tất khi nguyên nhân và một giải pháp được hỗ trợ đã được xác lập rõ ràng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- firebase, node.js, typescript
- Lĩnh vực
- backend, cloud
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100