CacheManager attempts to create file named guid.* on Windows (full example included and clear description)
还没有人认领这个 Issue。
评估
调研方向
疑似逻辑位于 lib/src/web/file_service.dart 第 115 行附近;首先在 Windows 上运行提供的最小复现,并跟踪 content-type 标头如何变成缓存文件名的扩展名。完成的标准是:对于标头未提供可用扩展名的下载,能够创建符合 Windows 要求的文件名,同时普通扩展名仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
🐛 Bug Report
While downloading an image from a webserver the cache manager decides to create a filename ending with .* which is not permitted on windows.
Expected behavior
Create a filename without extension or a generic extension like .cache or .file since the cache manager cannot determine it from the webserver headers.
Reproduction steps
i have made minimal reproducible example no external dependencies needed (other than http package)
i am aware that the server should provide correct descriptive headers for the content being served but sometimes it happens not to in some scenarios.
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
Future<void> main() async {
final client = MockClient((http.Request request) async =>
http.Response("a png image", 200, headers: {
"content-type": "application/*",
"content-disposition":
"attachment; filename=file; filename*=UTF-8''file"
}));
final cmgr = CacheManager(Config(DefaultCacheManager.key,
fileService: HttpFileService(httpClient: client)));
/* crashes with
Launching lib\main.dart on Windows in debug mode...
√ Built build\windows\runner\Debug\cache_mgr_test.exe.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot open file, path = 'C:\Users\csman\AppData\Local\Temp\libCachedImageData\cf09f070-6cef-1d8a-b096-2334712b3134.*' (OS Error: The filename, directory name, or volume label syntax is incorrect.
, errno = 123)
#0 _checkForErrorResponse (dart:io/common.dart:55:9)
#1 _File.open.<anonymous closure> (dart:io/file_impl.dart:381:7)
<asynchronous suspension>
*/
await cmgr.downloadFile("http://myaddress.com/imageManager?pngfileid=1234");
}
/*
pubspec.yaml
name: cache_mgr_test
description: A new Flutter project.
publish_to: "none"
version: 1.0.0+1
environment:
sdk: ">=3.1.5 <4.0.0"
dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_cache_manager: ^3.3.1
http: ^1.1.0
dev_dependencies:
flutter_lints: ^2.0.0
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
*/
Configuration
Version: 3.3.1
Platform:
Windows 10
I think the problematic part is in \flutter_cache_manager-3.3.1\lib\src\web\file_service.dart line 115 around
@override
String get fileExtension {
var fileExtension = '';
final contentTypeHeader = _header(HttpHeaders.contentTypeHeader);
if (contentTypeHeader != null) {
final contentType = ContentType.parse(contentTypeHeader);
fileExtension = contentType.fileExtension;
}
return fileExtension;
}
- 主要语言
- Dart
- 星标
- 810
- 派生
- 510
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 11
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Baseflow/flutter_cache_manager 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
Baseflow/flutter_cache_manager#450 · 9 条评论 · 8 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 30/100
-
难度 2/5 1-3 小时 新手友好度 48/100
Baseflow/flutter_cache_manager#507 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 30/100
Baseflow/flutter_cache_manager#501 · 1 条评论 · 3 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 45/100
Baseflow/flutter_cache_manager#500 · 1 条评论 · 3 个 reaction ·
查看 Baseflow/flutter_cache_manager 的全部 Issue
相似的 Issue
-
bug triage
难度 2/5 1-3 小时 新手友好度 70/100
fluttercommunity/plus_plugins#3979 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
from.page-issue
难度 1/5 1 小时以内 新手友好度 85/100
-
enhancement UI: Material
难度 2/5 1-3 小时 新手友好度 75/100
Notsfsssf/pixez-flutter#1360 ·
-
triage
难度 2/5 1-3 小时 新手友好度 70/100