uploadFileBytes method

Future<Map<String, String>> uploadFileBytes(
  1. Uint8List bytes,
  2. String remotePath, {
  3. String? mimeType,
})

Upload raw bytes as a file to a remote path.

Useful for programmatic uploads without a local file.

Implementation

Future<Map<String, String>> uploadFileBytes(
  Uint8List bytes,
  String remotePath, {
  String? mimeType,
}) async {
  final parentPath = p.dirname(remotePath);
  final fileName = p.basename(remotePath);
  final parent = await drive.resolveOrCreateFolder(parentPath);

  // Write to temp file, upload, clean up
  final tempDir = Directory.systemTemp.createTempSync('filen_upload_');
  final tempFile = File(p.join(tempDir.path, fileName));

  try {
    await tempFile.writeAsBytes(bytes);
    return await uploader.uploadFileChunked(tempFile, parent['uuid']);
  } finally {
    if (tempFile.existsSync()) tempFile.deleteSync();
    if (tempDir.existsSync()) tempDir.deleteSync();
  }
}