createFileFromRoot method
Implementation
Future<String?> createFileFromRoot(
String filename,
{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{
String? parent = scope == DriveApi.driveAppdataScope ? "appDataFolder" : "root";
var lastInd = filename.lastIndexOf("/");
if(lastInd != -1){
parent = await getIDFromRoot(filename.substring(0,lastInd));
if(parent == null) return null;
}
var fil = File(
modifiedTime: DateTime.now(),
appProperties: appProperties,
description: description,
parents: [parent],
name: filename.substring(lastInd+1),
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("createFileFromRoot:");
print("${e.toString()}\n${stack.toString()}");
}else if (onError != null){
onError!(e, stack);
}
return null;
}
}