firebase_storage 0.3.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Firebase Cloud Storage for Flutter #

pub package

A Flutter plugin to use the Firebase Cloud Storage API.

For Flutter plugins for other Firebase products, see

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage #

To use this plugin, add firebase_storage as a dependency in your pubspec.yaml file.

Getting Started #

See the example directory for a complete sample app using Firebase Cloud Storage.

0.3.5 #

  • Updated iOS implementation to reflect Firebase API changes.

0.3.4 #

  • Added timeout properties to FirebaseStorage

0.3.3 #

  • Added support for initialization with a custom Firebase app.

0.3.2 #

  • Added support for StorageReference writeToFile.

0.3.1 #

  • Added support for StorageReference functions: getParent, getRoot, getStorage, getName, getPath, getBucket.

0.3.0 #

  • Breaking change. Changed StorageUploadTask to abstract, removed the 'file' field, and made 'path' and 'metadata' private. Added two subclasses: StorageFileUploadTask and StorageDataUploadTask.
  • Deprecated the put function and added putFile and putData to upload files and bytes respectively.

0.2.6 #

  • Added support for updateMetadata.

0.2.5 #

  • Added StorageMetadata class, support for getMetadata, and support for uploading file with metadata.

0.2.4 #

  • Updated Google Play Services dependencies to version 15.0.0.

0.2.3 #

  • Updated package channel name and made channel visible for testing

0.2.2 #

  • Simplified podspec for Cocoapods 1.5.0, avoiding link issues in app archives.

0.2.1 #

  • Added support for getDownloadUrl.

0.2.0 #

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.1.5 #

  • Fix Dart 2 type errors.

0.1.4 #

  • Enabled use in Swift projects.

0.1.3 #

  • Added StorageReference path getter to retrieve the path component for the storage node.

0.1.2 #

  • Added StorageReference delete function to remove files from Firebase.

0.1.1 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.1.0 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.
  • Relaxed GMS dependency to [11.4.0,12.0[

0.0.8 #

  • Added FLT prefix to iOS types
  • Change GMS dependency to 11.4.+

0.0.7 #

  • Change GMS dependency to 11.+

0.0.6 #

  • Added StorageReference getData function to download files into memory.

0.0.5+1 #

  • Aligned author name with rest of repo.

0.0.5 #

  • Updated to Firebase SDK to always use latest patch version for 11.0.x builds
  • Fix crash when encountering upload failure

0.0.4 #

  • Updated to Firebase SDK Version 11.0.1

0.0.3 #

  • Suppress unchecked warnings

0.0.2 #

  • Bumped buildToolsVersion to 25.0.3
  • Updated README

0.0.1 #

  • Initial Release


// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:http/http.dart' as http;

void main() async {
  final FirebaseApp app = await FirebaseApp.configure(
    name: 'test',
    options: new FirebaseOptions(
      googleAppID: Platform.isIOS
          ? '1:159623150305:ios:4a213ef3dbd8997b'
          : '1:159623150305:android:ef48439a0cc0263d',
      gcmSenderID: '159623150305',
      apiKey: 'AIzaSyChk3KEG7QYrs4kQPLP1tjJNxBTbfCAdgg',
      projectID: 'flutter-firebase-plugins',
  final FirebaseStorage storage = new FirebaseStorage(
      app: app, storageBucket: 'gs://');
  runApp(new MyApp(storage: storage));

class MyApp extends StatelessWidget {
  final FirebaseStorage storage;

  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Storage Example',
      home: new MyHomePage(storage: storage),

class MyHomePage extends StatefulWidget {
  final FirebaseStorage storage;

  _MyHomePageState createState() => new _MyHomePageState();

const String kTestString = "Hello world!";

class _MyHomePageState extends State<MyHomePage> {
  String _fileContents;
  String _name;
  String _bucket;
  String _path;
  String _tempFileContents;

  Future<Null> _uploadFile() async {
    final Directory systemTempDir = Directory.systemTemp;
    final File file = await new File('${systemTempDir.path}/foo.txt').create();
    assert(await file.readAsString() == kTestString);
    final String rand = "${new Random().nextInt(10000)}";
    final StorageReference ref ='text').child('foo$rand.txt');
    final StorageUploadTask uploadTask =
        ref.putFile(file, const StorageMetadata(contentLanguage: "en"));

    final Uri downloadUrl = (await uploadTask.future).downloadUrl;
    final http.Response downloadData = await http.get(downloadUrl);
    final String name = await ref.getName();
    final String bucket = await ref.getBucket();
    final String path = await ref.getPath();

    final File tempFile = new File('${systemTempDir.path}/tmp.txt');
    if (tempFile.existsSync()) {
      await tempFile.delete();
    await tempFile.create();
    assert(await tempFile.readAsString() == "");
    final StorageFileDownloadTask task = ref.writeToFile(tempFile);
    final int byteCount = (await task.future).totalByteCount;
    final String tempFileContents = await tempFile.readAsString();
    assert(tempFileContents == kTestString);
    assert(byteCount == kTestString.length);

    setState(() {
      _fileContents = downloadData.body;
      _name = name;
      _path = path;
      _bucket = bucket;
      _tempFileContents = tempFileContents;

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('Flutter Storage Example'),
      body: new Center(
        child: new Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            _fileContents == null
                ? const Text('Press the button to upload a file \n '
                    'and download its contents to tmp.txt')
                : new Text(
                    'Success!\n Uploaded $_name \n to bucket: $_bucket\n '
                        'at path: $_path \n\nFile contents: "$_fileContents" \n'
                        'Wrote "$_tempFileContents" to tmp.txt',
                    style: const TextStyle(
                        color: const Color.fromARGB(255, 0, 155, 0)),
      floatingActionButton: new FloatingActionButton(
        onPressed: _uploadFile,
        tooltip: 'Upload',
        child: const Icon(Icons.file_upload),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  firebase_storage: ^0.3.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_storage/firebase_storage.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0