upload method

Future upload({
  1. required String name,
  2. required String content,
  3. DateTime? modifiedTime,
  4. List<String> parents = lazy.defaultGDriveParents,
})

Create remote file name with content

  • name is filename
  • content is String
  • parents default 'appDataFolder'
  • modifiedTime create remote file with supplied time if not null

Implementation

Future upload({
  required String name,
  required String content,
  DateTime? modifiedTime,
  List<String> parents = lazy.defaultGDriveParents,
}) async {
  String debugPrefix = '$runtimeType.upload()';
  lazy.log(debugPrefix);

  try {
    var file = lazy.gDriveFileMeta(
      name: name,
      modifiedTime: modifiedTime,
      parents: parents,
    );
    // [toMedia] use utf8 encoding
    var media = content.toMedia();
    lazy.log('$debugPrefix:size:${media.length}byte');
    // Upload/Create remote file
    var result = await create(file: file, uploadMedia: media);
    lazy.log('$debugPrefix:result(should be empty):\n${result.jsonPretty()}');
  } catch (e) {
    lazy.log('$debugPrefix:catch:$e');
  }
}