gpt4 book ai didi

dart - 下载 Google Drive 直接链接时如何显示正确的进度?

转载 作者:行者123 更新时间:2023-12-03 02:49:51 27 4
gpt4 key购买 nike

我有一个来自 Google Drive 的直接链接,我的应用程序将下载并显示百分比,它可以正确下载任何其他链接,但只有使用 Google Drive 直接链接,它才会显示一个很大的负数。

“Baixando”在葡萄牙语中的意思是“下载”。

app screen

  await dio.download(
widget.document['url'],
path,
onReceiveProgress: (received, total){

setState(() {
progress = "Baixando..."+((received / total) * 100).toStringAsFixed(0) + "%";
});

});

例如,使用此 Google Drive 直接链接 (pdf): https://drive.google.com/uc?export=download&id=1N8D8lx1HlW0X99wovGEQxZRUtewN6-J2

更新:“接收”以字节为单位获取文件的大小,“总计”我只得到值:-1,尝试下载 Google Drive 直接链接时它不会改变。

最佳答案

我检查了包的文档,这是示例代码:

await dio.download(url, "./example/flutter.svg",
options: Options(headers: {HttpHeaders.acceptEncodingHeader: "*"}), // disable gzip
onProgress: (received, total) {
if (total != -1) {
print((received / total * 100).toStringAsFixed(0) + "%");
}
});

它还指出:

When receiving data: total will be -1 if the size of the response body is not known in advance, for example: response data is compressed with gzip or no content-length header.



您没有在您的方法中执行此检查,因此当正在下载的文件的总大小未知时,您总是会得到那个大的负数。

只有 Google Drive 链接显示此行为的原因是缺少内容长度 header 或文件压缩。您可能需要找到从云端硬盘下载文件的替代方法。

关于dart - 下载 Google Drive 直接链接时如何显示正确的进度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56133492/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com