0
I need help with this question. I’m new to flutter. and can’t send more than 1 file at the same time to firebase with this code I can send 1 file without problems, but when selecting 2 files in the log shows the 2 files and in the firebase rises only 1 file with the name of the two files
import 'package:file_picker/file_picker.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class Estudos extends StatefulWidget {
@override
_EstudosState createState() => _EstudosState();
}
class _EstudosState extends State<Estudos> {
final FirebaseStorage storage = FirebaseStorage.instance;
String fileName;
String fileName;
List<PlatformFile> _paths;
final FileType _pickingType = FileType.custom;
final List<UploadTask> _tasks = <UploadTask>[];
Future<void> openFileExplorer() async {
setState(() {});
try {
_paths = (await FilePicker.platform.pickFiles(
type: _pickingType,
allowMultiple: true,
allowedExtensions: ['pdf', 'jpg'],
))
?.files;
} on PlatformException catch (e) {
//print("Unsupported operation" + e.toString());
} catch (ex) {
//print(ex);
}
if (!mounted) return;
setState(() {
fileName = _paths != null ? _paths.map((e) => e.name).toString() : '...';
getFilesToUpload();
});
}
final List<File> files = [];
void getFilesToUpload() {
_paths.forEach((path) => files.add(File(path.path)));
uploadFiles(files);
}
void uploadFiles(List<File> files) {
files.forEach((file) => uploadFireStorage(file));
}
Future uploadFireStorage([File file]) async {
final Reference pastaRaiz = storage.ref();
final Reference archive = pastaRaiz.child('estudos').child(fileName);
final UploadTask task = archive.putFile(file);
setState(() {
_tasks.add(task);
task.snapshotEvents.listen((TaskSnapshot storageEvent) {
if (storageEvent.state == TaskState.running) {
setState(() {
const CircularProgressIndicator();
});
} else if (storageEvent.state == TaskState.success) {
}
});
});
}```
I did the closest to that and continues with the same problem, when sending 2 files rises only 1 to firebase. I will update the code, if you have any suggestions I would appreciate
– Leo Gonzalez