uploadContent method

  1. @override
Future<Uri> uploadContent(
  1. Uint8List file, {
  2. String? filename,
  3. String? contentType,
})

Uploads a file and automatically caches it in the database, if it is small enough and returns the mxc url.

Implementation

@override
Future<Uri> uploadContent(Uint8List file,
    {String? filename, String? contentType}) async {
  final mediaConfig = await getConfig();
  final maxMediaSize = mediaConfig.mUploadSize;
  if (maxMediaSize != null && maxMediaSize < file.lengthInBytes) {
    throw FileTooBigSDNException(file.lengthInBytes, maxMediaSize);
  }

  contentType ??= lookupMimeType(filename ?? '', headerBytes: file);
  final mxc = await super
      .uploadContent(file, filename: filename, contentType: contentType);

  final database = this.database;
  if (database != null && file.length <= database.maxFileSize) {
    await database.storeFile(
        mxc, file, DateTime.now().millisecondsSinceEpoch);
  }
  return mxc;
}