flutter_cache_manager
flutter_cache_manager copied to clipboard
[flutter_cache_manager_firebase] PlatformException(download_error, Object does not exist at location., null, null)
🐛 Bug Report
I'm trying to get an audio file using a valid gs:// path and it's throwing a platform exception:
E/flutter ( 8213): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(download_error, Object does not exist at location., null, null)
E/flutter ( 8213): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:582
E/flutter ( 8213): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:159
E/flutter ( 8213): <asynchronous suspension>
E/flutter ( 8213): #2 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:332
E/flutter ( 8213): #3 StorageReference.getDownloadURL
package:firebase_storage/src/storage_reference.dart:142
E/flutter ( 8213): #4 FirebaseHttpFileService.get
package:flutter_cache_manager_firebase/src/firebase_http_file_service.dart:12
E/flutter ( 8213): #5 WebHelper._download
package:flutter_cache_manager/…/web/web_helper.dart:76
E/flutter ( 8213): #6 WebHelper._updateFile
package:flutter_cache_manager/…/web/web_helper.dart:58
E/flutter ( 8213): #7 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 8213): #8 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 8213): #9 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
I know it's a valid location too as replacing
final file = await FirebaseCacheManager().getSingleFile(audioURL);
with
final dir = (await getApplicationDocumentsDirectory()).path;
final filePath = path.join(dir, path.basename(audioURL));
final file = File(filePath);
final ref = await firebaseStorage.getReferenceFromUrl(audioURL);
await ref.writeToFile(file);
correctly fetches the file.
This library's current implementation calls getDownloadURL() but that creates a revokable token as a side effect and even has a potential rate cost (I read this in a SO post but can't find it). As a workaround, maybe could we replace this:
class FirebaseHttpFileService extends HttpFileService {
@override
Future<FileServiceResponse> get(String url,
{Map<String, String> headers = const {}}) async {
var ref = FirebaseStorage.instance.ref().child(url);
var _url = await ref.getDownloadURL() as String;
return super.get(_url);
}
}
with
class FirebaseHttpFileService extends HttpFileService {
@override
Future<FileServiceResponse> get(String url,
{Map<String, String> headers = const {}}) async {
var ref = await FirebaseStorage.instance.getReferenceFromUrl(url);
final streamedResponse =
StreamedResponse(ref.getData(32000).asStream(), 200);
return HttpGetResponse(streamedResponse);
}
}
Version: 1.x flutter_cache_manager_firebase: 1.0.1
[✓] Flutter (Channel dev, 1.23.0-18.0.pre, on Mac OS X 10.15.6 19G2021 x86_64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.7)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] Connected device (3 available)
• No issues found!
I don't know much about firebase storage, but looks good to me. Why would you choose a maximum size of about 32KB?
Sorry, should've left a comment about that. I'm not really sure what an appropriate allocation amount would be and just picked the first number that came to my head. Feel free to recommend
I'll see if I can't get a PR going too