llfbandit / dio_cache_interceptor

Dio HTTP cache interceptor with multiple stores respecting HTTP directives (ETag, Last-Modified, Cache-Control) with options.
https://pub.dev/packages/dio_cache_interceptor
120 stars 70 forks source link

When I use Dio to download a file, dio_cache_interceptor throws an error: Unhandled Exception: Unsupported operation: Response type not supported : ResponseType.stream. #155

Closed andrew2558 closed 5 months ago

andrew2558 commented 5 months ago

How should dio_cache_interceptor be configured to ignore the ResponseType.stream type? I haven't found the corresponding configuration. I am using the dio.download method to download files.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Response type not supported : ResponseType.stream.
#0      serializeContent (package:dio_cache_interceptor/src/util/content_serialization.dart:19:7)
#1      CacheResponse.writeContent (package:dio_cache_interceptor/src/model/cache_response.dart:260:17)
#2      DioCacheInterceptor._saveResponse (package:dio_cache_interceptor/src/dio_cache_interceptor.dart:226:25)
<asynchronous suspension>
#3      DioCacheInterceptor.onResponse (package:dio_cache_interceptor/src/dio_cache_interceptor.dart:102:5)
<asynchronous suspension>
flutter: Error setting audio source: (-1002) unsupported URL

dio download code:

response = await dio.download(urlPath, savePath,
        options: Options(responseType: ResponseType.stream, extra: {
          "extraIgnoreCacheKey": true,
        }), onReceiveProgress: (int count, int total) {
      print("$count $total");
    }, cancelToken: requestToken);
llfbandit commented 5 months ago

Yes ResponseType.stream is not supported.

You can make exceptions like this (pseudo code):

options: cacheOptions.copyWith(policy: CachePolicy.noCache).toOptions()