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:
parent
2b6ef23ab9
commit
02d7dd5be3
5 changed files with 36 additions and 4 deletions
|
|
@ -42,7 +42,7 @@ export const generateThumb = functions.storage.object().onFinalize(async object
|
||||||
const thumbnailLocalPath = join(workingDirectory, thumbnailName);
|
const thumbnailLocalPath = join(workingDirectory, thumbnailName);
|
||||||
|
|
||||||
await sharp(tmpFilePath)
|
await sharp(tmpFilePath)
|
||||||
.resize(124, 124)
|
.resize(256, 256)
|
||||||
.toFile(thumbnailLocalPath);
|
.toFile(thumbnailLocalPath);
|
||||||
|
|
||||||
// Upload the resulting thumnail to the same directory as the original file.
|
// Upload the resulting thumnail to the same directory as the original file.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:rxdart/rxdart.dart';
|
import 'package:rxdart/rxdart.dart';
|
||||||
|
|
@ -31,6 +32,9 @@ class EventBloc {
|
||||||
Observable<List<TaskModel>> get eventTasks =>
|
Observable<List<TaskModel>> get eventTasks =>
|
||||||
_tasks.stream.transform(kTaskListPriorityTransforemer);
|
_tasks.stream.transform(kTaskListPriorityTransforemer);
|
||||||
|
|
||||||
|
Future<File> get testFile => _storage.getFile(
|
||||||
|
'26LVkBPFkHVekVDatitVh6MXrm53/thumb@c64293a0-5970-11e9-d441-03e3ea627257.png');
|
||||||
|
|
||||||
EventBloc({
|
EventBloc({
|
||||||
@required this.eventName,
|
@required this.eventName,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
export 'package:firebase_storage/firebase_storage.dart'
|
export 'package:firebase_storage/firebase_storage.dart'
|
||||||
show StorageUploadTask, StorageTaskSnapshot;
|
show StorageUploadTask, StorageTaskSnapshot;
|
||||||
|
|
||||||
|
|
@ -42,6 +44,22 @@ class FirebaseStorageProvider {
|
||||||
Future<void> deleteFile(String path) {
|
Future<void> deleteFile(String path) {
|
||||||
return _storage.child(path).delete();
|
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();
|
final storageProvider = FirebaseStorageProvider();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../utils.dart' show kBigTextStyle;
|
import '../utils.dart' show kBigTextStyle;
|
||||||
|
|
@ -93,9 +95,16 @@ class _EventScreenState extends State<EventScreen>
|
||||||
|
|
||||||
Widget buildMediaView() {
|
Widget buildMediaView() {
|
||||||
return Center(
|
return Center(
|
||||||
child: Text(
|
child: FutureBuilder(
|
||||||
'Media',
|
future: bloc.testFile,
|
||||||
style: kBigTextStyle,
|
builder: (BuildContext context, AsyncSnapshot<File> snap) {
|
||||||
|
if (!snap.hasData) {
|
||||||
|
return Center(
|
||||||
|
child: LoadingIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Image.file(snap.data);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ dependencies:
|
||||||
http: ^0.12.0
|
http: ^0.12.0
|
||||||
image_picker: ^0.5.0+3
|
image_picker: ^0.5.0+3
|
||||||
mockito: ^4.0.0
|
mockito: ^4.0.0
|
||||||
|
path_provider: ^0.5.0+1
|
||||||
rxdart: ^0.20.0
|
rxdart: ^0.20.0
|
||||||
sqflite: ^1.1.0
|
sqflite: ^1.1.0
|
||||||
uuid: ^2.0.0
|
uuid: ^2.0.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue