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

feat(firebase_storage_web): web support #3917

Merged
merged 42 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
72524a0
flutter create -t plugin
ditman Oct 2, 2020
96302d6
First pass at the plugin. Compiler seems happy, but no actual testing.
ditman Oct 7, 2020
a1cf72a
Push 'success' snapshot to the onStateChangedStream
ditman Oct 14, 2020
90daa3e
Document CORS setup so Reference getData() works.
ditman Oct 20, 2020
e9e21fe
Handle errors on getDownloadURL
ditman Oct 20, 2020
9ba0d60
Handle errors from futures and streams. Call .toList when initializin…
ditman Oct 21, 2020
1771fee
Ensure the Task.onComplete future throws the correct type of exception.
ditman Oct 22, 2020
e91d9c0
Introduce the SettableMetadataCache helper.
ditman Oct 23, 2020
0a51a2d
Reuse the reference that created a task for its snapshots.
ditman Oct 26, 2020
b8a52a3
Add unit tests for metadata_cache.dart
ditman Oct 27, 2020
f7f08e7
Mark package as -dev.
ditman Oct 28, 2020
d06faf3
Remove state from TaskSnapshotWeb constructor.
ditman Oct 28, 2020
af7b350
Add scaffolding for test_driver (and tests for task_snapshot)
ditman Oct 28, 2020
8f68c58
Make analyzer happy
ditman Oct 28, 2020
0b68675
Making package validation happy
ditman Oct 28, 2020
18ebaae
Lazily subscribe to the underlying streams of a Task.
ditman Oct 30, 2020
882913d
Move mocks to a separate file.
ditman Oct 30, 2020
db6f842
Add tests for TaskWeb
ditman Oct 30, 2020
0da5813
Use storage instance to recreate refs in list result, instead of a ne…
ditman Oct 30, 2020
1f5a9c3
Tests for ListResultWeb (and dartfmt for Task tests)
ditman Oct 30, 2020
8219473
Rename fb.Storage from storage to fbStorage to not confuse it with th…
ditman Oct 30, 2020
da580af
Some tweaks to ReferenceWeb, and some tests (WIP)
ditman Oct 30, 2020
c2b5aa6
Test put* methods in reference_web
ditman Nov 3, 2020
4e50c98
Mark overrides and provide a way to create a mock instance of the Fir…
ditman Nov 3, 2020
962539d
Tests for FirebaseStorageWeb and dartfmt -w .
ditman Nov 3, 2020
490b823
Keep track of maxOperationRetryTime; the getter seems to be undefined…
ditman Nov 3, 2020
4d5d0cd
Ensure delete errors are converted to the correct type.
ditman Nov 3, 2020
f6dfaf4
dartfmt -w .
ditman Nov 3, 2020
9d2c358
Make UploadTask pause and cancel wait for the internal state to be co…
ditman Nov 4, 2020
47c23c6
Update pubspec to latest published code.
ditman Nov 4, 2020
261da3a
Add license headers and fix flutter analyze
ditman Nov 4, 2020
dc8a4de
Fix CHANGELOG
ditman Nov 4, 2020
5aec412
convert delegate calls to try/catch
Ehesp Nov 19, 2020
5f49f45
add web plugin to registry
Ehesp Nov 19, 2020
8667d08
Merge branch 'master' into firebase-storage-web
Salakar Nov 19, 2020
3e8d411
ci: enable storage web CI
Salakar Nov 19, 2020
35c94a6
docs: update storage web platform availability flags
Salakar Nov 19, 2020
e79fdd5
Merge branch 'master' into firebase-storage-web
Ehesp Nov 19, 2020
ade557d
chore: add example firebase configuration
Salakar Nov 19, 2020
4b6a17f
fix: add firebase_storage_web as a dependency on firebase_storage
Salakar Nov 19, 2020
c5c953c
refactor: remove firebase_storage_web git dep from example
Salakar Nov 19, 2020
c22208d
fix: match up versions to latest published packages
Salakar Nov 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions .github/workflows/firebase_storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ jobs:
- name: "Drive MacOS Example"
run: ./.github/workflows/scripts/drive-example.sh macos

# TODO: enable once web support lands.
# web:
# runs-on: ubuntu-latest
# timeout-minutes: 15
# steps:
# - uses: actions/checkout@v1
# with:
# fetch-depth: 0
# - name: "Install Flutter"
# run: ./.github/workflows/scripts/install-flutter.sh beta
# - name: "Install Tools"
# run: |
# ./.github/workflows/scripts/install-tools.sh
# flutter config --enable-web
# - name: "Drive Example"
# run: ./.github/workflows/scripts/drive-example.sh web
web:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh beta
- name: "Install Tools"
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-web
- name: "Drive Example"
run: ./.github/workflows/scripts/drive-example.sh web
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ videos. [[Learn More][storage_product]]

| Android | iOS | MacOS | Web |
|:-------:|:---:|:-----:|:---:|
| ✔️ | ✔️ | ✔️ | |
| ✔️ | ✔️ | ✔️ | ✔️ |

----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ dependencies:
path: ../../../firebase_core/firebase_core
image_picker: ^0.6.7
image_picker_for_web: ^0.1.0
firebase_storage_web:
git:
url: https://github.com/ditman/flutterfire.git
ref: firebase-storage-web
path: packages/firebase_storage/firebase_storage_web

dependency_overrides:
firebase_core:
Expand Down
20 changes: 13 additions & 7 deletions packages/firebase_storage/firebase_storage/example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
<title>Firebase Storage Web Example</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.5.0/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {

apiKey: "AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0",
authDomain: "react-native-firebase-testing.firebaseapp.com",
databaseURL: "https://react-native-firebase-testing.firebaseio.com",
projectId: "react-native-firebase-testing",
storageBucket: "react-native-firebase-testing.appspot.com",
messagingSenderId: "448618578101",
appId: "1:448618578101:web:772d484dc9eb15e9ac3efc",
measurementId: "G-0N1G9FLDZE"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
Expand Down
3 changes: 3 additions & 0 deletions packages/firebase_storage/firebase_storage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ flutter:
pluginClass: FLTFirebaseStoragePlugin
macos:
pluginClass: FLTFirebaseStoragePlugin
web:
default_package: firebase_storage_web

dependencies:
flutter:
sdk: flutter
firebase_core: ^0.5.2
firebase_core_platform_interface: ^2.0.0
firebase_storage_web: ^0.1.0
firebase_storage_platform_interface: ^1.0.1
quiver: ^2.1.3

Expand Down
7 changes: 7 additions & 0 deletions packages/firebase_storage/firebase_storage_web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
10 changes: 10 additions & 0 deletions packages/firebase_storage/firebase_storage_web/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: b63970c6815320dfa731a8a329d9118c62244ecc
channel: master

project_type: plugin
3 changes: 3 additions & 0 deletions packages/firebase_storage/firebase_storage_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial open source release.
27 changes: 27 additions & 0 deletions packages/firebase_storage/firebase_storage_web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 changes: 60 additions & 0 deletions packages/firebase_storage/firebase_storage_web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# firebase_storage_web

The web implementation of `firebase_storage`.

## Getting Started

To get started with Firebase Storage, please [see the documentation](https://firebase.flutter.dev/docs/storage/overview)
available at [https://firebase.flutter.dev](https://firebase.flutter.dev)

Once installed, Firebase Storage needs to be configured for Web Installation. Please [see the documentation](https://firebase.flutter.dev/docs/storage/overview#3-web-only-add-the-sdk) on Web Installation

To learn more about Firebase Storage, please visit the [Firebase website](https://firebase.google.com/products/storage)

## Downloading files with `getData()`

When using `Reference::getData()` in the web platform, your bucket must have the correct CORS configuration, or the security mechanisms in the browser will *not* let you access the downloaded data, with exceptions similar to:

```
Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com/v0/b/...example.txt?alt=media&token=1234-4321-1234-4321-12341234' from origin 'http://your-web-app.domain.com:PORT' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
```

```
browser_client.dart:87 GET https://firebasestorage.googleapis.com/v0/b/...example.txt?alt=media&token=1234-4321-1234-4321-12341234 net::ERR_FAILED
```

or

```
Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 894:28 get current
packages/http/src/browser_client.dart 84:22 <fn>
```

You need to enable CORS response headers in your Google Cloud Storage Bucket, as described in the following document:

* Firebase > Docs > Guides > [Download Files on Web](https://firebase.google.com/docs/storage/web/download-files).

In the `example` app, ensure there's a `cors.json` file:

```
firebase_storage/example$ cat cors.json
[
{
"origin": ["*"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
```

And then, with `gsutil`:

```
firebase_storage/example$ gsutil cors set cors.json gs://my-example-bucket.appspot.com
Setting CORS on gs://my-example-bucket.appspot.com/...
```

For much, much more information about CORS in Google Cloud Platform, see:

* Storage products > Cloud Storage > Documentation > [Configuring cross-origin resource sharing (CORS)](https://cloud.google.com/storage/docs/configuring-cors)
46 changes: 46 additions & 0 deletions packages/firebase_storage/firebase_storage_web/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
10 changes: 10 additions & 0 deletions packages/firebase_storage/firebase_storage_web/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 8d80592d46db57628ed71e2727b86427a944595b
channel: master

project_type: app
16 changes: 16 additions & 0 deletions packages/firebase_storage/firebase_storage_web/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# example

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Loading