Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling getDownloadURL in favor of directly getting data #241

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
// Generated file. Do not edit.
//

// ignore: unused_import
import 'dart:ui';

import 'package:url_launcher_web/url_launcher_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(PluginRegistry registry) {
UrlLauncherPlugin.registerWith(registry.registrarFor(UrlLauncherPlugin));
registry.registerMessageHandler();
void registerPlugins(Registrar registrar) {
UrlLauncherPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
3 changes: 3 additions & 0 deletions flutter_cache_manager_firebase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.1.1-beta] - 2020-10-21
* Replace getDownloadURL with getData to avoid token creation

## [1.1.0-beta] - 2020-10-02
* Update CacheManager dependency to 2.x.x.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:io';

import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;

/// [FirebaseHttpFileService] is another common file service which parses a
/// firebase reference into, to standard url which can be passed to the
Expand All @@ -8,9 +11,24 @@ 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;
final ref = FirebaseStorage.instance.refFromURL(url);
final metaData = await ref.getMetadata();
final headers = {
HttpHeaders.contentTypeHeader: metaData.contentType,
HttpHeaders.contentLanguageHeader: metaData.contentLanguage,
HttpHeaders.dateHeader:
metaData.timeCreated.millisecondsSinceEpoch.toString(),
HttpHeaders.contentLocationHeader: metaData.fullPath,
};
if (metaData.cacheControl != null) {
headers[HttpHeaders.cacheControlHeader] = metaData.cacheControl;
}
final response = http.StreamedResponse(
ref.getData(metaData.size).asStream(),
200,
headers: headers,
);

return super.get(_url);
return HttpGetResponse(response);
}
}
8 changes: 4 additions & 4 deletions flutter_cache_manager_firebase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_cache_manager_firebase
description: CacheManager implementation for firebase_storage. Uses the gs:// as key and translates to https://
version: 1.1.0-beta
version: 1.1.1-beta
homepage: https://github.com/Baseflow/flutter_cache_manager

environment:
Expand All @@ -10,9 +10,9 @@ dependencies:
flutter:
sdk: flutter
flutter_cache_manager: ^2.0.0-beta
firebase_storage: '>=3.0.0 <5.0.0'
path_provider: "^1.4.0"
path: "^1.6.4"
firebase_storage: ^7.0.0
path_provider: ^1.4.0
path: ^1.6.4

dev_dependencies:
flutter_test:
Expand Down