Added a function that downloads a file from the storage bucket given its path, change the size of the thumnails to 256 per side

This commit is contained in:
Mariano Uvalle 2019-04-07 20:29:51 -05:00
parent 2b6ef23ab9
commit 02d7dd5be3
5 changed files with 36 additions and 4 deletions

View file

@ -42,7 +42,7 @@ export const generateThumb = functions.storage.object().onFinalize(async object
const thumbnailLocalPath = join(workingDirectory, thumbnailName);
await sharp(tmpFilePath)
.resize(124, 124)
.resize(256, 256)
.toFile(thumbnailLocalPath);
// Upload the resulting thumnail to the same directory as the original file.

View file

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';
@ -31,6 +32,9 @@ class EventBloc {
Observable<List<TaskModel>> get eventTasks =>
_tasks.stream.transform(kTaskListPriorityTransforemer);
Future<File> get testFile => _storage.getFile(
'26LVkBPFkHVekVDatitVh6MXrm53/thumb@c64293a0-5970-11e9-d441-03e3ea627257.png');
EventBloc({
@required this.eventName,
});

View file

@ -2,7 +2,9 @@ import 'dart:async';
import 'dart:io';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';
export 'package:firebase_storage/firebase_storage.dart'
show StorageUploadTask, StorageTaskSnapshot;
@ -42,6 +44,22 @@ class FirebaseStorageProvider {
Future<void> deleteFile(String path) {
return _storage.child(path).delete();
}
// TODO: Add tests for this method.
// TODO: Delete the tmp file when the app closes.
/// Returns a future of the file from the path.
///
/// Downloads the raw bytes from the sotrage buckets and converts it to a file.
Future<File> getFile(String path) async {
final fileName = path.split('/').last;
final fileReference = _storage.child(path);
final metadata = await fileReference.getMetadata();
final bytes = await fileReference.getData(metadata.sizeBytes);
final Directory tmp = await getTemporaryDirectory();
final file = File('${tmp.path}/$fileName');
return file.writeAsBytes(bytes);
}
}
final storageProvider = FirebaseStorageProvider();

View file

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import '../utils.dart' show kBigTextStyle;
@ -93,9 +95,16 @@ class _EventScreenState extends State<EventScreen>
Widget buildMediaView() {
return Center(
child: Text(
'Media',
style: kBigTextStyle,
child: FutureBuilder(
future: bloc.testFile,
builder: (BuildContext context, AsyncSnapshot<File> snap) {
if (!snap.hasData) {
return Center(
child: LoadingIndicator(),
);
}
return Image.file(snap.data);
},
),
);
}

View file

@ -31,6 +31,7 @@ dependencies:
http: ^0.12.0
image_picker: ^0.5.0+3
mockito: ^4.0.0
path_provider: ^0.5.0+1
rxdart: ^0.20.0
sqflite: ^1.1.0
uuid: ^2.0.0