uploadToPath method
Upload a local file to a remote path.
Example: client.uploadToPath(File('report.pdf'), '/Documents/');
Implementation
Future<Map<String, String>> uploadToPath(
File localFile,
String remotePath, {
bool preserveTimestamps = false,
}) async {
// Determine if remotePath is a directory or a full file path
String parentPath;
if (remotePath.endsWith('/')) {
parentPath = remotePath;
} else {
// Check if it resolves to a folder
try {
final resolved = await resolvePath(remotePath);
if (resolved['type'] == 'folder') {
parentPath = remotePath;
} else {
parentPath = p.dirname(remotePath);
}
} catch (_) {
parentPath = p.dirname(remotePath);
}
}
final parent = await drive.resolveOrCreateFolder(parentPath);
String? cTime, mTime;
if (preserveTimestamps) {
final stat = await localFile.stat();
mTime = stat.modified.millisecondsSinceEpoch.toString();
cTime = stat.changed.millisecondsSinceEpoch.toString();
}
return uploader.uploadFileChunked(
localFile,
parent['uuid'],
creationTime: cTime,
modificationTime: mTime,
);
}