createFile method

Future<String?> createFile(
  1. String filename, {
  2. String? mimeType,
  3. Map<String, String?>? appProperties,
  4. String? description,
  5. Stream<List<int>>? data,
  6. int? dataLength,
})

Implementation

Future<String?> createFile(
    String filename,
    {String? mimeType,
    Map<String, String?>? appProperties,
    String? description,
    Stream<List<int>>? data,
    int? dataLength}
) async{
  if(!await ready()) return null;
  if(dataLength != null && !await hasSpace(dataLength)){
    if(onFull != null) onFull!();
    return null;
  }
  try{
    String? parent = wd;
    var lastInd = filename.lastIndexOf("/");
    if(lastInd != -1){
      parent = await getID(filename.substring(0,lastInd));
      if(parent == null) return null;
    }
    var fil = File(
      // spaces: [(scope == DriveApi.driveAppdataScope) ? "appDataFolder" : "drive"],
      modifiedTime: DateTime.now(),
      appProperties: appProperties,
      description: description,
      parents: [parent],
      name: filename.substring(lastInd+1),
      mimeType: mimeType,
    );
    fil = await api!.files.create(
      fil,
      uploadMedia: (data != null) ? Media(data, dataLength) : null
    );
    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("createFile:");
      print("${e.toString()}\n${stack.toString()}");
    }else if (onError != null){
      onError!(e, stack);
    }
    return null;
  }
}