uploadProfilePicture method

Future<Reference> uploadProfilePicture(
  1. File image,
  2. String uploadDirectory,
  3. int id,
  4. Function? imagePostProcessingFuction,
)

Implementation

Future<Reference> uploadProfilePicture(File image, String uploadDirectory,
    int id, Function? imagePostProcessingFuction) async {
  final String uploadPath = '$uploadDirectory${id.toString()}_800.jpg';
  final Reference imgRef = _storageInstance.ref().child(uploadPath);

  // start upload
  final UploadTask uploadTask =
      imgRef.putFile(image, new SettableMetadata(contentType: 'image/jpg'));

  // wait until upload is complete
  try {
    await uploadTask;
  } on Exception catch (error, stackTrace) {
    throw Exception('Upload failed, Firebase Error: $error $stackTrace');
  }

  return imgRef;
}