google / googleapis.dart

Repository for building the googleapis packages
https://pub.dev/packages/googleapis
BSD 3-Clause "New" or "Revised" License
393 stars 118 forks source link

drive api download File - how to listen file size progress? #615

Closed wengxianxun closed 2 weeks ago

wengxianxun commented 5 months ago
drive.Media dataStream = await driveApi!.files.get(fileEntry.id!,
        downloadOptions: drive.DownloadOptions.fullMedia) as drive.Media;
    int totalLength = dataStream.length!;
    String path = '${Persistence.videoDir.path}/${TimeUtils.timestamp()}.mp4';
    io.File file = io.File(path);
    final writer = file.openWrite();
    await writer.addStream(dataStream.stream);
    await writer.close(); 

how to listen file size progress?

WorldpixelSoftware commented 1 month ago

I have the same problem. I'd like to show some progress while downloading the drive files, but the File.length property on my drive files fetched by the DriveAPIv3 are always null.

kevmoo commented 2 weeks ago

You could wrap the Stream and log output as it makes progress.

You could put a StreamController in the middle and listen to events on that.

WorldpixelSoftware commented 1 week ago

You could wrap the Stream and log output as it makes progress.

You could put a StreamController in the middle and listen to events on that.

Hi @kevmoo Could you give a quick example please? I'm not 100% sure how I would get the progress out of this (like x/xmb downloaded or x% or something)? Since I would need the stream length beforehand or the file size. The stream length will imply first listening to the stream (but that means the data will already have been transfered) and the latter is always null when I try to fetch that. Thank you.