-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[firebase_storage]: Out of memory error when uploading large files (1GB) on newer versions of firebase_storage and firebase_core #13460
Comments
Hi @Fudal , thanks for submitting this issue. We are currently looking into it. |
Hi @Fudal , Thank you for sharing the details of the issue. I tried reproducing the error using the code you provided, but I encountered an "out of memory" error during the _prepareLargeFiles() method while generating the 1GB files, rather than during the upload process itself. Could you clarify whether the "out of memory" error you're seeing happens during file preparation or upload? |
@SelaseKay My production code is different than what is shown here, in my case the large files are video recordings created earlier, I do not create them as shown here in the example code. |
Thanks for the clarification |
Please let me know if there's anything else I can do or add. I'm very keen to use the latest versions of the libraries, as other dependencies are also adapted to the Firebase version. |
I'm currently working on reproducing the issue on my end. I assumed you'd tested the reproducible code, which is why I raised my earlier question. |
I was able to reproduce this issue. Steps to Reproduce
import 'dart:async';
import 'dart:io' as io;
import 'dart:io';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'firebase_options.dart';
import 'save_as/save_as.dart';
import 'package:path_provider/path_provider.dart';
import 'package:file_picker/file_picker.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
class FileUploadScreen extends StatefulWidget {
@override
_FileUploadScreenState createState() => _FileUploadScreenState();
}
class _FileUploadScreenState extends State<FileUploadScreen> {
List<File> _selectedFiles = [];
bool _isUploading = false;
Future<void> _selectFiles() async {
final result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result != null) {
setState(() {
_selectedFiles = result.paths.map((path) => File(path!)).toList();
});
}
}
Future<void> _uploadFiles() async {
if (_selectedFiles.isEmpty) return;
setState(() {
_isUploading = true;
});
try {
for (final file in _selectedFiles) {
String fileName = file.path.split('/').last;
Reference storageRef = FirebaseStorage.instance.ref().child('flutter-tests').child('uploads/$fileName');
UploadTask uploadTask = storageRef.putFile(file, SettableMetadata(contentType: 'video/mp4'));
await uploadTask.whenComplete(() {
print('File Uploaded: $fileName');
});
}
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('All files uploaded successfully!')),
);
} catch (e) {
print('Error uploading files: $e');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Error uploading files. Please try again.')),
);
} finally {
setState(() {
_isUploading = false;
_selectedFiles.clear();
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('File Upload Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _selectFiles,
child: const Text('Select Files'),
),
const SizedBox(height: 20),
Text('Selected Files: ${_selectedFiles.length}'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _isUploading ? null : _uploadFiles,
child: const Text('Upload Files'),
),
if (_isUploading) const CircularProgressIndicator(),
],
),
),
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FileUploadScreen(),
);
}
} Logs
|
Is there an existing issue for this?
Which plugins are affected?
Storage
Which platforms are affected?
Android, iOS
Description
I am experiencing an issue with the firebase_storage library in my Flutter app. The problem occurs when I try to upload large files (around 1GB) to Firebase Storage.
When using the following versions of the libraries:
firebase_storage: 11.7.7
firebase_core: 2.32.0
I consistently encounter an "out of memory" error and my app crashes when trying to upload the 12th recording (around 1GB).
However, with the following older versions of the libraries:
firebase_storage: 11.3.1
firebase_core: 2.19.0
I am able to upload up to 30 recordings (1GB each) without any issues or crashes.
This problem seems to be specific to the newer versions of the firebase_storage and firebase_core libraries. Every version above 11.3.1 of firebase_storage and 2.19.0 of firebase_core appears to trigger the same "out of memory" error and app crashes.
I would appreciate if the maintainers of the firebase_storage library could look into this issue and provide a fix or workaround, as the newer versions of the library are crucial for keeping my app up-to-date.
Reproducing the issue
Firebase Core version
11.7.7
Flutter Version
3.24.3
Relevant Log Output
Flutter dependencies
Expand
Flutter dependencies
snippetAdditional context and comments
Any assistance in resolving this issue would be greatly appreciated, as it's critical for the functionality of my app. Thank you for your time and effort.
The text was updated successfully, but these errors were encountered: