createFileWithParent method

Future<String?> createFileWithParent(
  1. String filename,
  2. String parentId, {
  3. String? mimeType,
  4. Map<String, String?>? appProperties,
  5. String? description,
  6. int initialSizeCheck = 1048576,
})

Implementation

Future<String?> createFileWithParent(
    String filename,
    String parentId,
    {String? mimeType,
    Map<String, String?>? appProperties,
    String? description,
    //initialSizeCheck defaults to 1MB which should be enough for most text-based uses (json). Large files should specify an amount that is approximately the file size.
    int initialSizeCheck = 1048576}
) async {
  if(!await ready()) return null;
  if(!await hasSpace(initialSizeCheck)){
    if(onFull != null) onFull!();
    return null;
  }
  try{
    var fil = File(
      modifiedTime: DateTime.now(),
      appProperties: appProperties,
      description: description,
      parents: [parentId],
      name: filename,
      mimeType: mimeType,
    );
    fil = await api!.files.create(fil);
    return fil.id;
  }catch(e, stack){
    if(e is PlatformException && e.code == "network_error"){
      return null;
    }
    // else if(e is DetailedApiRequestError && e.message == "The user's Drive storage quota has been exceeded."){
    //   if(onFull != null) onFull!();
    //   return null;
    // }
    if(kDebugMode){
      print("createFileWithParent:");
      print("${e.toString()}\n${stack.toString()}");
    }else if (onError != null){
      onError!(e, stack);
    }
    return null;
  }
}