Fixed a bug where all the thumnails where the same as the first one in the firebase function

This commit is contained in:
Mariano Uvalle 2019-04-07 19:08:18 -05:00
parent f438df4432
commit 2b6ef23ab9
3 changed files with 11 additions and 4 deletions

View file

@ -10,17 +10,22 @@ import * as sharp from 'sharp';
import * as fs from 'fs-extra';
export const generateThumb = functions.storage.object().onFinalize(async object => {
// Find the bucket where the uploaded dile resides.
// Find the bucket where the uploaded file resides.
const bucket = gcs.bucket(object.bucket);
// Find the path of the file inside the bucket.
const filePathGcs = object.name;
// Save the name of the file.
const fileName = filePathGcs!.split('/').pop();
// Directory where the file is stored inside the bucket.
const bucketDirectory = dirname(filePathGcs!);
const workingDirectory = join(tmpdir(), 'thumbnails');
const tmpFilePath = join(workingDirectory, 'source.png');
const tmpFilePath = join(workingDirectory, fileName!);
if (fileName!.includes('thumb@') || !object.contentType!.includes('image')) {
console.log('Exiting function');
console.log('Exiting function, already compressed or no image.');
return false;
}

View file

@ -34,7 +34,7 @@ class FirebaseStorageProvider {
_storage.child('$folder$fileId.$type');
return fileReference.putFile(
file,
StorageMetadata(contentType: 'image'),
StorageMetadata(contentType: 'image/png'),
);
}

View file

@ -140,12 +140,14 @@ class _NewImageScreenState extends State<NewImageScreen> {
Navigator.of(context).pop();
}
// TODO: Pro users can save their pictures in full res.
/// Prompts the user to take a picture.
///
/// Updates the file in the bloc.
Future<void> takePicture() async {
final File imgFile = await ImagePicker.pickImage(
source: ImageSource.camera,
maxWidth: 1500,
);
bloc.changePicture(imgFile);
}