upload method
- String filePath
Uploads a file to the Liquid Galaxy.
requires the filePath
of the file to upload.
Implementation
Future<void> upload(String filePath) async {
if (!await isConnected()) {
return;
}
try {
// Load file data from assets
final ByteData data = await rootBundle.load(filePath);
// Extract the file name from the provided filePath
final fileName = filePath.split('/').last;
final sftp = await client!.sftp();
// Upload file directly from byte data
final remoteFile = await sftp.open(
'/var/www/html/$fileName',
mode: SftpFileOpenMode.create | SftpFileOpenMode.write,
);
// Convert ByteData to Uint8List and write it directly
final uint8ListData = data.buffer.asUint8List();
await remoteFile.write(Stream.value(uint8ListData).cast<Uint8List>());
await remoteFile.close();
} catch (e) {
print('Error during file upload: $e');
}
}